Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a docker container stop?

Tags:

docker

If there is a simple run command specified on the command line, or with CMD, the container stops when the program exits. But, what if:

  • the program spawns new processes, ant then exits?

  • 'exec' is used on the command line, then the first command exits?

Can you please also point to the docs?

Thanks!

like image 581
Hristo Hristov Avatar asked Mar 17 '23 03:03

Hristo Hristov


1 Answers

The process you run when you exec docker run will be the process with PID 1 (inside the process namespace of the container). This process is special in UNIX / Linux systems and it's the process in charge of 'adopting' any 'orphaned' process. If this process ends, all the processes will end also.

So, answering your questions, if this initial process (the one executed in docker run) ends, all the processes inside your container will also end . I have not found any official documentation related to this, but there is a great post from phusion discussing about this topic.

like image 182
Javier Cortejoso Avatar answered Mar 29 '23 16:03

Javier Cortejoso