Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker running nginx using daemon off instance Analysis

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "docker running nginx using daemon off case analysis", the content is detailed, the steps are clear, and the details are handled properly. I hope that this "docker running nginx using daemon off case analysis" article can help you solve your doubts.

problem

Why did the 1.docker container hang up when it was running?

By default, the docker container takes the first process within the container, that is, the program of pid=1, as the basis for whether the docker container is running or not. If the docker container pid fails, then the docker container will exit directly.

2.docker run uses command as the internal command of the container. If you use nginx, the nginx program will run in the background. At this time, nginx is not a program with a pid of 1, but an executing bash. The bash executes the nginx instruction and then hangs, so the container exits. For the same reason as yours, after pm2 start, the pid of bash is 1, then the bash will exit after execution, so the container will exit.

Now I'll use an example to tell why we do Thiskeeper!

Touch file get_pid

Echo "pid of this script: $$" echo "ppid of this script: $ppid" echo "uid of this script: $uid" # nginx-g 'daemon off;'

At this point, we start the container to execute the sh file

Odtoy:~ zhaojunlike$ eval `docker-machine env default`godkeeper: ~ zhaojunlike$ cd workspace/godtoy:workspace zhaojunlike$ lsdocker nodejs php pid_getgodtoy:workspace zhaojunlike$ vim pid_getgodtoy:workspace zhaojunlike$ docker run-v `pwd` / pid_get:/pid_get:ro-- rm-- workdir=/ nginx bash / pid_getpid of this script: 1ppid of this script: 0uid of this script: 0godtoy:workspace zhaojunlike$

After the container executes the pid_get, the container automatically exits, and at this point, it prints that the current bash is running with a pid of 1.

So, if we want to keep the container alive, then unguarded execution is necessary, and of course the following can also be done inside a container.

Godtoy:workspace zhaojunlike$ docker run-it nginx bashroot@a8baa5fe77f0:/# nginxroot@a8baa5fe77f0:/# godtoy:workspace zhaojunlike$

We use the-it parameter to connect to the pipe inside the container, and then we use the nginx command inside the container. Finally, after ctrl+p+q exits the container, the container is still running.

After reading this, the article "docker running nginx using daemon off instance Analysis" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report