After entering the Docker container, if you exit the container, the container will change to the Exited state. So how do you exit the container without shutting down the container? If you want to exit normally without closing the container, press Ctrl+P+Q to exit the container. This is very important, please remember! The following example exits the container without closing it: [root@localhost ~]# docker attach c600c4519fc8 [root@c600c4519fc8 /]# exit exit [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c600c4519fc8 centos "/bin/bash" 3 hours ago Exited (0) 1 second ago pensive_jackson 5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan 4b0296d18849 hello-world "/hello" 46 hours ago Exited (0) 46 hours ago hopeful_yonath [root@localhost ~]# docker start pensive_jackson pensive_jackson [root@localhost ~]# docker attach c600c4519fc8 Ctrl + P + Q [root@c600c4519fc8 /]# read escape sequence [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c600c4519fc8 centos "/bin/bash" 3 hours ago Up 22 seconds pensive_jackson 5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan 4b0296d18849 hello-world "/hello" 46 hours ago Exited (0) 46 hours ago hopeful_yonath In fact, we can configure it when starting the container and add the -d parameter to start the container. Of course, this command is limited to starting a new container, and it is not possible to start a closed container. Tips 1 docker run -d: runs the container in the background and returns the container ID The following example uses docker -d to start a container and exit [root@localhost ~]# docker run -i -t -d centos /bin/bash 8521b11d5d99535d4cb0080adc5a58a4dd018ecd0751d9945f7da7ab01bec330 [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8521b11d5d99 centos "/bin/bash" 4 seconds ago Up 4 seconds eager_goldwasser c600c4519fc8 centos "/bin/bash" 3 hours ago Exited (0) 28 seconds ago pensive_jackson 5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan 4b0296d18849 hello-world "/hello" 46 hours ago Exited (0) 46 hours ago hopeful_yonath [root@localhost ~]# docker attach 8 [root@8521b11d5d99 /]# uname -r 3.10.0-514.el7.x86_64 [root@8521b11d5d99 /]# exit exit [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8521b11d5d99 centos "/bin/bash" 2 minutes ago Exited (0) 2 seconds ago eager_goldwasser c600c4519fc8 centos "/bin/bash" 3 hours ago Exited (0) 2 minutes ago pensive_jackson 5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan 4b0296d18849 hello-world "/hello" 46 hours ago Exited (0) 46 hours ago hopeful_yonath Here you may find that the container is still dead after exiting with the -d command. Hands-on friends may find that just starting the container with docker run -d is also dead. What we need to understand here is the operating 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 running, so that the container can survive after -d is started. [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c600c4519fc8 centos "/bin/bash" 3 hours ago Exited (0) 4 minutes ago pensive_jackson 5a7a0d694651 busybox "sh" 21 hours ago Exited (0) 21 hours ago hungry_vaughan 4b0296d18849 hello-world "/hello" 47 hours ago Exited (0) 47 hours ago hopeful_yonath [root@localhost ~]# docker run -d centos /bin/bash -c "nohup ping -i 1000 www.baidu.com" 8aa19c9604382bc019797ccda831ae1bcebd81d86380b6040d636e03000b440a [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8aa19c960438 centos "/bin/bash -c 'nohup..." 2 seconds ago Up 2 seconds adoring_wing c600c4519fc8 centos "/bin/bash" 3 hours ago Exited (0) 5 minutes ago pensive_jackson 5a7a0d694651 busybox "sh" 21 hours ago Exited (0) 21 hours ago hungry_vaughan 4b0296d18849 hello-world "/hello" 47 hours ago Exited (0) 47 hours ago hopeful_yonath I use nohup to run a process in the background that pings Baidu every 1000 seconds. 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, the container will still be terminated. Please keep this in mind. Ctrl+P+Q is still the best method in my opinion. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: MySQL gets the current date and time function
>>: Two methods to implement Mysql remote connection configuration
Create a table create table order(id varchar(10),...
This article describes how to export and import ....
Table of contents 1. Introduction 2. Implementati...
Features of SSHFS: Based on FUSE (the best usersp...
When a web project gets bigger and bigger, its CS...
To facilitate the maintenance of MySQL, a script ...
Preface Before starting this article, let’s do a ...
The :not pseudo-class selector can filter element...
for loop The for loop loops through the elements ...
1. Understanding of transition attributes 1. The ...
Table of contents Create a table View the databas...
Because the router at home forced to reduce the b...
1. Introduction I have been studying the principl...
When I was writing a project yesterday, I needed ...
This article describes MySQL multi-table query wi...