Why just played a docker container to run automatically withdrawn?
phenomenon:
From a container #docker run -d --name mycentos-zp3 -d centos with docker run command: 7.4.1708
Container just run automatically withdrawn
source:
After check in online reasons, Docker container running in the background, there must be a foreground process, the command vessel if it is not running those commands have been suspended (such as running top
, tail), is automatically exit
This is a docker mechanisms, such as your web container, we fpm and nginx for example,
under normal circumstances, we only need to configure the service to start to start the service response, for example,
service nginx start && service php5-fpm start
However, to do so, nginx and background processes are fpm mode, it causes the application is not running in the foreground docker,
such containers, backstage after the start, will immediately commit suicide because he felt he nothing to do up.
Solution:
Set a start command only can avoid this issue, set the startup command (be sure to set the command does not automatically exit)
docker run -d --name mycentos-zp4 -d centos:7.4.1708 ping 8.8.8.8
docker run -d --name mycentos-zp5 -d centos:7.4.1708 /bin/sh -c "while true;do echo hello;sleep 5;done"