Home>Article>Operation and Maintenance> Docker container does not stop exiting
In docker, you can press the "Ctrl P Q" key to exit the container without stopping; if you exit the container after entering the docker container, the container will become Exited. "Ctrl P Q" will exit the container and the container will not stop. will stop.
The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.
If you exit the container after entering the docker container, the container will become Exited. So how do you exit the container so that the container does not close?
If you want to exit normally without closing the container, please press Ctrl P Q to exit the container. This is very important, please remember!
The following example exits the container but does not close the container
In fact, we can configure it when starting the container and add the -d parameter to start the container , of course, this command is only limited to starting new containers, starting closed containers is not allowed.
Tips 1
docker run -d: Run the container in the background and return the container ID
The following example uses docker -d to start the container and exit
Here you may find that the container is still dead after using the -d command to exit. A hands-on friend may find that just using docker run -d to start the container is also dead
What you actually need to understand here is the running mechanism of the container. The Docker container runs in the background and must have a foreground process. Here we let the container have a foreground program to run, so that the container can survive after startup with -d
I use nohup to run a process in the background that pings Baidu every 1000 seconds. In addition, you can also use "while true; do echo hello world; sleep 1; done", unlimited Output hello world.
In addition, even if there is a process running in the background, if you enter the container and enter exit to exit, the running of the container will still be terminated, please bear in mind.
Recommended learning: "docker video tutorial"
The above is the detailed content of Docker container does not stop exiting. For more information, please follow other related articles on the PHP Chinese website!