There are too many pitfalls in installing nginx with docker, so give up decisively

The following is my personal opinion. If there is anything wrong, you can discuss and communicate in the comment area.
1. The port of listen is limited by the parameters of docker -p. An nginx container conf file can only listen to the same port.
2. It is troublesome to modify the configuration file. There is docker exec to enter the container to operate (of course, -v can be mounted)
3. For the second point, it is generally necessary to mount multiple resources (of course, before mounting, you must first execute the docker cp command, and the container Copy the files in the host to the host machine, which is troublesome, and then mount it to the container to facilitate synchronous modification)

docker run  --name nginx -m 200m -p 80:80 \
-v /docker-work/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /docker-work/nginx/logs:/var/log/nginx \
-v /docker-work/nginx/html:/usr/share/nginx/html \
-v /docker-work/nginx/conf:/etc/nginx/conf.d \
-e TZ=Asia/Shanghai \
--privileged=true -d nginx
参数说明
-name  给你启动的容器起个名字,以后可以使用这个名字启动或者停止容器
-p     映射端口,将docker宿主机的80端口和容器的80端口进行绑定
-v    挂载文件用的,
-m 200m 分配内存空间
-e TZ=Asia/Shanghai  设置时区
第一个-v 表示将你本地的nginx.conf覆盖你要起启动的容器的nginx.conf文件,
第二个-v 表示将日志文件进行挂载,就是把nginx服务器的日志写到你docker宿主机的/home/docker-nginx/log/下面
第三个-v 表示的和第一个-v意思一样的。
-d 表示启动的是哪个镜像

4. No matter how I modify the nginx.conf file, it will not work (I only use docker restart to restart). I can’t find the reason after a long time of comparison. The conf file inside the container is also changed synchronously. Use nginx -t to check the syntax. is ok.
Then I abandoned docker to install nginx, and installed the nginx.tar package directly in the linux environment, and it will take effect in ten minutes.
Attach the nginx installation tutorial: link

Guess you like

Origin blog.csdn.net/lzq2357639195/article/details/129927361