Dockerfileでapacheとmysqlサービスを持つミラーを構築し、supervisorを使用してプロセスを管理します.

5950 ワード

この記事では、前編のミラーリングに基づいてDockerfileでapacheサービスを備えたベースUbuntuミラーリングを構築しアップロードし、mysqlサービスを拡張し、supervisorを使用してプロセスを管理しています.私たちは常に1つのマシンで複数のサービスを開く必要があります.これは多くの方法があります.最も簡単なのは、複数の起動コマンドを1つの起動スクリプトに入れ、起動時に直接このスクリプトを起動し、またプロセス管理ツールをインストールすることです.プロセス管理ツールsupervisorは起動プロセスを管理し、Supervisorを使用すると、実行したいプロセスをよりよく制御、管理、再起動することができます.DockerはSupervisorを使用してプロセスを管理
1.ファイルディレクトリとファイルの作成
必要なディレクトリmysqlの作成ubuntuはDockerfileと関連ファイルを格納するために使用されます.
$ mkdir mysql_ubuntu/
$ cd mysql_ubuntu/
$ touch Dockfile supervisord.conf

2. supervisord.confファイルの内容
supervisord.confはsupervisorプロファイルで、プロファイルにはディレクトリとプロセスが含まれており、最初のsupervsord構成ソフトウェア自体はnodaemonパラメータを使用して実行されます.第2セグメントには、制御する2つのサービスが含まれています.各セグメントには、サービスのディレクトリと、このサービスを起動するコマンドが含まれます.
nodaemon=true
[program:apache2]
command=/usr/sbin/apache2 -DFOREGROUND
[program:mysql]
command=/usr/bin/mysqld_safe

3.Dockerfileファイルの内容
#build mysql image
#
# VERSION 1.0

FROM nssczh/apache:ubuntu
MAINTAINER NSS/Czh

RUN     apt-get update \
        && echo "#!/bin/sh
exit 0"
> /usr/sbin/policy-rc.d \ && DEBIAN_FRONTEND="noninteractive" apt-get install -y mysql-server supervisor\ && rm -rf /var/lib/apt/lists/* # supervisord , 。 COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf RUN /etc/init.d/mysql start \ &&mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'xidian320';" \ &&mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'xidian320';" \ &&mysql -u root -pxidian320 -e "show databases;" RUN sed -i "s/bind-address/#bind-address/g" /etc/mysql/my.cnf EXPOSE 3306 CMD ["/usr/bin/supervisord"]

4.ミラーの作成とテスト
$ docker build -t mysql:6.0 .
...
Successfully built 52b4bcf7cecc
Successfully tagged mysql:6.0
$ docker run -d -P mysql:6.0 
$ docker ps -a
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                    PORTS                                            NAMES
18d4c24a8bae        mysql:6.0              "/usr/bin/supervisord"   8 seconds ago       Up 5 seconds              0.0.0.0:32793->80/tcp, 0.0.0.0:32792->3306/tcp   practical_swanson

テストapache:ブラウザにコンテナがあるip+ポート番号を入力します.http://192.168.8.95:32793/を選択すると、apacheの初期ページが表示されます.mysqlのテスト:コマンドmysql -h 192.168.8.95 -u root -pxidian320 -P 32792でコンテナのmysqlに接続できます.
$ mysql -h 192.168.8.95 -u root -pxidian320 -P 32792
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

5.ミラーのアップロード
ミラーをdocker hubウェアハウスにアップロードするには、REPOSTORYをユーザーdocker idに変更する必要があります.
$ docker tag mysql:6.0 nssczh/mysql:ubuntu
$ docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ docker push nssczh/mysql:ubuntu
...
ubuntu: digest: sha256:34cc36c241bc8359006034faebbb1b9de79a203652d17a32d5e9dd3b3533db87 size: 2617