Get the App
SLTechnology News&Howtos  ›  Servers  › 

Docker-compose deployment LNMP

Shulou Source: shulou.com Published: 2022-06-02 23:20:15 09月16日 Update

Prepare before the experiment:

Download:

[root@localhost] # curl-L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname-s-uname-m`-o / usr/local/bin/docker-compose

[root@localhost ~] # chmod + x / usr/local/bin/docker-compose

[root@localhost] # docker-compose-v

Docker-compose version 1.25.1-rc1, build d92e9bee

/ / Import the image

[root@localhost ~] # docker load

< nginx.tar && docker load < php.7.2-fpm.tar && docker load < mysql-5.7.tar //复制配置文件 [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 [root@localhost ~]# docker cp test:/etc/nginx /root/compose-lnmp/docker/br/>

[root@localhost ~] # docker cp test:/etc/nginx / root/compose-lnmp/docker/

Br/ > [root@localhost ~] # vim / root/compose-lnmp/wwwroot/html/index.html

Hello LNMP!

/ / add php test interface [root@localhost ~] # vim / root/compose-lnmp/wwwroot/html/test.phpbr/ > [root@localhost ~] # vim / root/compose-lnmp/wwwroot/html/test.php

/ / set the number of spaces for the tab key [root@localhost ~] # vim .vimrcbr / > [root@localhost ~] # vim .vimrc

Br/ > [root@localhost ~] # cat .vimrc

/ / write docker-compose.yml file [root@localhost ~] # cd / root/compose-lnmp/br/ > [root@localhost ~] # cd / root/compose-lnmp/

Version: "3.1"

Services:

Nginx:

Container_name: nginx

Image: nginx

Networks:

Lnmp:

Ipv4_address: 172.16.10.10

Restart: always

Ports:

80:80

Volumes:/root/compose-lnmp/wwwroot/html:/usr/share/nginx/html/root/compose-lnmp/docker/nginx:/etc/nginx

Mysql:

Container_name: mysql

Image: mysql:5.7

Networks:

Lnmp:

Ipv4_address: 172.16.10.20

Restart: always

Ports:3306:3306

Environment:

MYSQL_ROOT_PASSWORD: 123.com

Php:

Container_name: phpfpm

Image: php:7.2-fpm

Networks:

Lnmp:

Ipv4_address: 172.16.10.30

Restart: always

Ports:9000:9000

Volumes:/root/compose-lnmp/wwwroot/html:/usr/share/nginx/html

Networks:

Lnmp:

Driver: bridge

Ipam:

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

/ / modify nginx configuration file, nginx and php connect [root@localhost compose-lnmp] # cd docker/nginx/conf.d/br/ > [root@localhost compose-lnmp] # cd docker/nginx/conf.d/

10 lines:

Location / {

Root / usr/share/nginx/html

Index index.html index.htm index.php; / / add php parsing

}

/ / Open this module and change the appropriate information:

30 lines:

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

}

/ / restart

[root@localhost conf.d] # docker-compose restart

/ / php and mysql connection [root@localhost compose-lnmp] # cd wwwroot/html/br/ > [root@localhost compose-lnmp] # cd wwwroot/html/

[root@localhost html] # mv phpMyAdmin-4.9.1-all-languages phpmyadmin

/ / change the nginx configuration file [root@localhost compose-lnmp] # cd docker/nginx/conf.d/br/ > [root@localhost compose-lnmp] # cd docker/nginx/conf.d/

/ / add on line 27

Location / phpmyadmin {

Root / usr/share/nginx/html

Index index.html index.htm index.php

}

/ / add on line 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

}

/ / restart

[root@localhost conf.d] # docker-compose restart

/ / you need to make changes to the php image. Write a Dockerfile for modules that add php and mysql connections.

[root@localhost ~] # vim Dockerfilebr/ > write a Dockerfile

[root@localhost ~] # vim Dockerfile

RUN 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.

/ / Delete the container, change the docker-compose.yml file, and rerun [root@localhost compose-lnmp] # docker-compose stopbr/ > [root@localhost compose-lnmp] # docker-compose stop

Br/ > [root@localhost compose-lnmp] # vim docker-compose.yml

Image: phpmysql

[root@localhost compose-lnmp] # docker-compose up-d

/ / modify the configuration file of phpmyadmin, specify the IP to connect to the database, and then restart [root@localhost compose-lnmp] # cd wwwroot/html/phpmyadmin/br/ > [root@localhost compose-lnmp] # cd wwwroot/html/phpmyadmin/

Br/ > [root@localhost phpmyadmin] # vim config.inc.php

[root@localhost phpmyadmin] # cd-br/ > $cfg ['Servers'] [$] [' host'] = '172.16.10.20'

[root@localhost phpmyadmin] # cd-

[root@localhost compose-lnmp] # docker-compose restart

/ / visit again

User name: root

Password: 123.com

Tags: File configuration module mirror information again container password data database quantity user name interface space prepare experiment test run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Microsoft macOS MariaDB