Install Nginx using Docker

This article mainly describes how to use docker to install the nginx image, and mount the files in the docker to the physical machine
1. Download the Nginx image

docker pull nginx

2. Create a mount folder locally

/Users/zhanghao/data/nginx/conf/
/Users/zhanghao/data/nginx/conf.d/
/Users/zhanghao/data/nginx/html/
/Users/zhanghao/data/nginx/logs/

Note: Create according to your own path, and use the directory created here to mount the subsequent startup command.
3. Start a non-mounted container and copy out the configuration file

docker run --name nginx-test -d -p 80:80 nginx
docker cp nginx-test:/etc/nginx/nginx.conf /Users/zhanghao/data/nginx/conf/nginx.conf
docker cp nginx-test:/etc/nginx/conf.d/default.conf /Users/zhanghao/data/nginx/conf.d/default.conf
docker cp nginx-test:/usr/share/nginx/html/50x.html /Users/zhanghao/data/nginx/html/
docker cp nginx-test:/usr/share/nginx/html/index.html /Users/zhanghao/data/nginx/html/

4. Close and delete the temporarily created container

docker stop nginx-test
docker rm nginx-test

5. Start the mounted container

docker run --name nginx1 -p 80:80 -v /Users/zhanghao/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /Users/zhanghao/data/nginx/conf.d:/etc/nginx/conf.d -v /Users/zhanghao/data/nginx/html:/usr/share/nginx/html -v /Users/zhanghao/data/nginx/logs:/var/log/nginx -d nginx

6. Test
Visit http:127.0.0.1 nginx welcome page

Original link: https://blog.csdn.net/qq_42114918/article/details/85238011

Guess you like

Origin blog.csdn.net/qq_21033663/article/details/104120238