Install and start Nginx in Docker (stand-alone version)

1. Obtain the nginx configuration file

1) Randomly start an nginx instance, just to copy out the configuration

docker run -p 80:80 --name nginx -d nginx:1.10

2) Copy the configuration file in the container to the current directory

cd /mydata
docker <container> cp nginx:/etc/nginx /mydata/nginx

3) Modify the file name: mv nginx conf, and then create a new nginx directory and move this conf to /mydata/nginx

#最终目录结构
- mydata
 - nginx
  - conf   #conf里面就是我们复制出来的所有内容 	

4) Terminate the original container: docker stop nginx

5) Execute the command to delete the original container: docker rm $ContainerId

2. Formally create nginx

docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx \
-v /mydata/nginx/conf:/etc/nginx \
-d nginx:1.10

Guess you like

Origin blog.csdn.net/weixin_44485316/article/details/131867136