docker-compose LNMP配備
5012 ワード
実験前準備:ダウンロード:[root@localhost ~]# curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s
//ミラーのインポート[root@localhost ~]# docker load
//プロファイルのコピー[root@localhost ~]# mkdir -p compose-lnmp/docker/[root@localhost ~]# cd compose-lnmp/[root@localhost compose-lnmp]# mkdir wwwroot
[root@localhost ~]# docker run -itd --name test nginx:latest br/>[root@localhost ~]# docker cp test:/etc/nginx /root/compose-lnmp/docker/ [root@localhost ~]# docker cp test:/usr/share/nginx/html /root/compose-lnmp/wwwroot br/>[root@localhost ~]# vim /root/compose-lnmp/wwwroot/html/index.html [root@localhost ~]# cat /root/compose-lnmp/wwwroot/html/index.html hello LNMP!
//phpテストインタフェースを追加br/>[root@localhost ~]# vim /root/compose-lnmp/wwwroot/html/test.php [root@localhost ~]# cat /root/compose-lnmp/wwwroot/html/test.php phpinfo(); ?>
//tabキーのスペース数br/>[root@localhost ~]# vim .vimrc [root@localhost ~]# source .vimrc br/>[root@localhost ~]# cat .vimrc set tabstop=2
//docker-composeを書く.ymlファイルbr/>[root@localhost ~]# cd /root/compose-lnmp/ [root@localhost compose-lnmp]# vim docker-compose.yml version: "3.1"services:nginx:container_name: nginximage: nginxnetworks:lnmp:ipv4_address: 172.16.10.10restart: alwaysports: 80:80volumes: /root/compose-lnmp/wwwroot/html:/usr/share/nginx/html /root/compose-lnmp/docker/nginx:/etc/nginxmysql:container_name: mysqlimage: mysql:5.7networks:lnmp:ipv4_address: 172.16.10.20restart: alwaysports: 3306:3306environment:MYSQL_ROOT_PASSWORD: 123.comphp:container_name: phpfpmimage: php:7.2-fpmnetworks:lnmp:ipv4_address: 172.16.10.30restart: alwaysports: 9000:9000volumes: /root/compose-lnmp/wwwroot/html:/usr/share/nginx/htmlnetworks:lnmp:driver: bridgeipam:config: subnet: 172.16.10.0/24
[root@localhost ~]# echo net.ipv4.ip_forward = 1 >>/etc/sysctl.conf [root@localhost ~]# systemctl restart network
[root@localhost compose-lnmp]# docker-compose up -d
//nginxプロファイルの変更、nginxとphp接続br/>[root@localhost compose-lnmp]# cd docker/nginx/conf.d/ [root@localhost conf.d]# vim default.conf 10行:location/{root/usr/share/nginx/html;index index.html index.html.html index.html index.htm index.php;//php解析を追加//このモジュールを開き、対応する情報を変更します:30行:location~.php$ { root /usr/share/nginx/html; fastcgi_pass 172.16.10.30:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}//再起動[root@localhost conf.d]# docker-compose restart
//phpとmysql接続br/>[root@localhost compose-lnmp]# cd wwwroot/html/ [root@localhost html]# unzip phpMyAdmin-4.9.1-all-languages.zip [root@localhost html]# mv phpMyAdmin-4.9.1-all-languages phpmyadmin
//nginxプロファイルの変更br/>[root@localhost compose-lnmp]# cd docker/nginx/conf.d/ [root@localhost conf.d]# vim default.conf//27行にlocation/phpmyadmin{root/usr/share/nginx/html;index index.html index.html.html index.htmlを追加}//43行にlocation~/phpmyadmin/(?.*)を追加します.(php|php5)?$) { root /usr/share/nginx/html; fastcgi_pass 172.16.10.30:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
//再起動[root@localhost conf.d]# docker-compose restart
//phpミラーを変更し、phpとmysqlの接続を追加するモジュールbr/>Dockerfileを書く必要があります[root@localhost ~]# vim Dockerfile FROM php:7.2-fpmRUN apt-get update && apt-get install -y\libfreetype6-dev\libjpeg62-turbo-dev\libpng-dev\&& docker-php-ext-install -j$(nproc) iconv\&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/--with-jpeg-dir=/usr/include/\&& docker-php-ext-install -j$(nproc) gd\&& docker-php-ext-install mysqli pdo pdo_mysql[root@localhost ~]# docker build -t phpmysql .
//コンテナを削除し、docker-composeを変更します.ymlファイルを再実行し、br/>[root@localhost compose-lnmp]# docker-compose stop [root@localhost compose-lnmp]# docker-compose rm br/>[root@localhost compose-lnmp]# vim docker-compose.yml//phpで使用したミラーを先ほど作成したミラーimage:phpmysqlに変更[root@localhost compose-lnmp]# docker-compose up -d
//phpmyadminのプロファイルを変更し、データベースに接続するIPを指定し、br/>[root@localhost compose-lnmp]# cd wwwroot/html/phpmyadmin/ [root@localhost phpmyadmin]# cp config.sample.inc.php config.inc.php br/>[root@localhost phpmyadmin]# vim config.inc.php 31行:br/>$cfg['Servers'][$i]['host']='172.16.10.20'; [root@localhost phpmyadmin]# cd - /root/compose-lnmp [root@localhost compose-lnmp]# docker-compose restart
//再アクセスユーザー名:rootパスワード:123.com
-
uname -m` -o/usr/local/bin/docker-compose[root@localhost ~]# chmod +x/usr/local/bin/docker-compose[root@localhost ~]# docker-compose -vdocker-compose version 1.25.1-rc1, build d92e9bee //ミラーのインポート[root@localhost ~]# docker load
//プロファイルのコピー[root@localhost ~]# mkdir -p compose-lnmp/docker/[root@localhost ~]# cd compose-lnmp/[root@localhost compose-lnmp]# mkdir wwwroot
[root@localhost ~]# docker run -itd --name test nginx:latest br/>[root@localhost ~]# docker cp test:/etc/nginx /root/compose-lnmp/docker/ [root@localhost ~]# docker cp test:/usr/share/nginx/html /root/compose-lnmp/wwwroot br/>[root@localhost ~]# vim /root/compose-lnmp/wwwroot/html/index.html [root@localhost ~]# cat /root/compose-lnmp/wwwroot/html/index.html hello LNMP!
//phpテストインタフェースを追加br/>[root@localhost ~]# vim /root/compose-lnmp/wwwroot/html/test.php [root@localhost ~]# cat /root/compose-lnmp/wwwroot/html/test.php phpinfo(); ?>
//tabキーのスペース数br/>[root@localhost ~]# vim .vimrc [root@localhost ~]# source .vimrc br/>[root@localhost ~]# cat .vimrc set tabstop=2
//docker-composeを書く.ymlファイルbr/>[root@localhost ~]# cd /root/compose-lnmp/ [root@localhost compose-lnmp]# vim docker-compose.yml version: "3.1"services:nginx:container_name: nginximage: nginxnetworks:lnmp:ipv4_address: 172.16.10.10restart: alwaysports:
[root@localhost ~]# echo net.ipv4.ip_forward = 1 >>/etc/sysctl.conf [root@localhost ~]# systemctl restart network
[root@localhost compose-lnmp]# docker-compose up -d
//nginxプロファイルの変更、nginxとphp接続br/>[root@localhost compose-lnmp]# cd docker/nginx/conf.d/ [root@localhost conf.d]# vim default.conf 10行:location/{root/usr/share/nginx/html;index index.html index.html.html index.html index.htm index.php;//php解析を追加//このモジュールを開き、対応する情報を変更します:30行:location~.php$ { root /usr/share/nginx/html; fastcgi_pass 172.16.10.30:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}//再起動[root@localhost conf.d]# docker-compose restart
//phpとmysql接続br/>[root@localhost compose-lnmp]# cd wwwroot/html/ [root@localhost html]# unzip phpMyAdmin-4.9.1-all-languages.zip [root@localhost html]# mv phpMyAdmin-4.9.1-all-languages phpmyadmin
//nginxプロファイルの変更br/>[root@localhost compose-lnmp]# cd docker/nginx/conf.d/ [root@localhost conf.d]# vim default.conf//27行にlocation/phpmyadmin{root/usr/share/nginx/html;index index.html index.html.html index.htmlを追加}//43行にlocation~/phpmyadmin/(?.*)を追加します.(php|php5)?$) { root /usr/share/nginx/html; fastcgi_pass 172.16.10.30:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
//再起動[root@localhost conf.d]# docker-compose restart
//phpミラーを変更し、phpとmysqlの接続を追加するモジュールbr/>Dockerfileを書く必要があります[root@localhost ~]# vim Dockerfile FROM php:7.2-fpmRUN apt-get update && apt-get install -y\libfreetype6-dev\libjpeg62-turbo-dev\libpng-dev\&& docker-php-ext-install -j$(nproc) iconv\&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/--with-jpeg-dir=/usr/include/\&& docker-php-ext-install -j$(nproc) gd\&& docker-php-ext-install mysqli pdo pdo_mysql[root@localhost ~]# docker build -t phpmysql .
//コンテナを削除し、docker-composeを変更します.ymlファイルを再実行し、br/>[root@localhost compose-lnmp]# docker-compose stop [root@localhost compose-lnmp]# docker-compose rm br/>[root@localhost compose-lnmp]# vim docker-compose.yml//phpで使用したミラーを先ほど作成したミラーimage:phpmysqlに変更[root@localhost compose-lnmp]# docker-compose up -d
//phpmyadminのプロファイルを変更し、データベースに接続するIPを指定し、br/>[root@localhost compose-lnmp]# cd wwwroot/html/phpmyadmin/ [root@localhost phpmyadmin]# cp config.sample.inc.php config.inc.php br/>[root@localhost phpmyadmin]# vim config.inc.php 31行:br/>$cfg['Servers'][$i]['host']='172.16.10.20'; [root@localhost phpmyadmin]# cd - /root/compose-lnmp [root@localhost compose-lnmp]# docker-compose restart
//再アクセスユーザー名:rootパスワード:123.com