The first one, nginx and php are placed in two mirrors
dnmp: https://github.com/yeszao/dnmp , this document and configuration are relatively complete, or directly pull the mirror image of php and nginx in the official, but you need to mount and connect by yourself
Pull
git clone https://github.com/yeszao/dnmp.git
implement
cd dnmp/
cp env.sample .env
cp docker-compose.sample.yml docker-compose.yml
docker-compose up
# 如果提示没有docker-compose
apt install docker-comopose
Start the container
docker start cfe
docker exec -it cfe /bin/bash
directory mount
docker run -it -v /data/dnmp/www:/www dnmp_php /bin/sh
stop container
docker stop cfe
The second type, nginx and php are placed in a mirror
webdevops/php-nginx: https://hub.docker.com/r/webdevops/php-nginx , a relatively official hybrid image
pull image
docker pull webdevops/php-nginx
create container
docker run -itd --name php-nginx-xs -p 80:80 -v /data/www/:/data/www webdevops/php-nginx
into the corresponding container
docker exce -it eb3 /bin/sh
possible problem
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
Replace /bin/bash with /bin/sh successfully
Detailed explanation: Docker data volume directory mount
Check
nginx -t
php -v
mount
docker run -d -v /data/www:/data/www -p 8080:80 --privileged=true webdevops/php-nginx
-
-d run the startup process silently in the background
-
-v /data/www:/data/www maps the host data volume to the directory of the docker container (data volume name: /container directory)
-
-p 8080:80 maps the port of the host to the port of the docker container (host port: container port)
-
--privileged=true grant privileges
-
The nginx image to be started by webdevops/php-nginx docker run to create and start the container
Reference: Deploy LNMP environment using docker container and mirror php-nginx |
other
-i: Run the container in interactive mode, usually used together with -t
-t: Reassign a pseudo-input terminal for the container, usually used together with -i;
Reference: docker quickly builds a php7.2-nginx development environment - Tiny Humans - Blog Park
Documentation library: Detailed explanation of docker -v command - mount directory or mount file - Geek library