Home>Article>Operation and Maintenance> How to solve the problem of Docker exiting the container without closing the container

How to solve the problem of Docker exiting the container without closing the container

WJ
WJ Original
2020-06-08 17:06:23 4330browse

How to solve the problem of Docker exiting the container without closing the container

How to solve the problem that Docker exits the container without closing the container?

If you exit the docker container after entering it, the container will become Exited. So how to exit the container so that the container does not close?

If you want to exit normally without closing the container, please pressCtrl P Qto exit the container. This is very important, please remember!

The following example exits the container but does not close it

How to solve the problem of Docker exiting the container without closing the container

In fact, we can configure it when starting the container and join -d parameter to start the container. Of course, this command can only start a new container, not a closed container.

Tips 1

docker run -d: Run the container in the background and return the container ID

The following example usesdocker - dStart the container and exit

How to solve the problem of Docker exiting the container without closing the container

Here you may find that the container is still dead after using the -d command to exit, hands-on friends You 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 there must be a foreground process. Here we let the container have a foreground program running, so that the container can survive after -d startup

How to solve the problem of Docker exiting the container without closing the container

I use nohup to run one in the background and ping every 1000 seconds. Baidu's process, you can also use "while true; do echo hello world; sleep 1; done" to output hello world infinitely.

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.

Ctrl P Qis still the best usage in my opinion.

Related references:docker tutorial

The above is the detailed content of How to solve the problem of Docker exiting the container without closing the container. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn