In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge about why docker runs nginx and uses daemon off. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
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.
These are all the contents of the article "Why docker runs nginx and uses daemon off". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.