In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Docker enables the exit container not to close the container. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
After entering the docker container, if you exit the container, 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, press Ctrl+P+Q to exit the container, which is very important, please keep in mind!
The following example exits the container without closing the container
[root@localhost ~] # docker attach c600c4519fc8 [root@c600c4519fc8 /] # exitexit [root@localhost ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc600c4519fc8 centos "/ bin/bash" 3 hours ago Exited (0) 1 second ago pensive_jackson5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan4b0296d18849 hello- World "/ hello" 46 hours ago Exited (0) 46 hours ago hopeful_ Yonath [root @ localhost ~] # docker start pensive_jacksonpensive_ Jackson [root @ localhost ~] # docker attach c600c4519fc8Ctrl + P + Q [root@c600c4519fc8 /] # read escape sequence [root@localhost ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc600c4519fc8 centos "/ bin/bash" 3 hours ago Up 22 seconds pensive_jackson5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan4b0296d18849 hello-world "/ hello" 46 hours ago Exited (0) 46 hours ago hopeful_yonath
In fact, we can configure the container when we start it, adding 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 is to start the container and exit using docker-d
[root@localhost ~] # docker run-I-t-d centos / bin/bash8521b11d5d99535d4cb0080adc5a58a4dd018ecd0751d9945f7da7ab01bec330 [root@localhost ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8521b11d5d99 centos "/ bin/bash" 4 seconds ago Up 4 seconds eager_goldwasserc600c4519fc8 centos "/ bin/bash" 3 hours ago Exited (0) 28 seconds ago pensive_jackson5a7a0d694651 Busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan4b0296d18849 hello-world "/ hello" 46 hours ago Exited (0) 46 hours ago hopeful_ Yonath [root @ localhost ~] # docker attach 8 [root@8521b11d5d99 /] # uname-r3.10.0-514.el7.x86_64 [root@8521b11d5d99 /] # exitexit [root@localhost ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8521b11d5d99 centos "/ bin/bash" 2 minutes ago Exited (0) 2 seconds ago eager_goldwasserc600c4519fc8 centos "/ bin/bash" 3 hours ago Exited (0) 2 minutes ago pensive_jackson5a7a0d694651 busybox "sh" 20 hours ago Exited (0) 20 hours ago hungry_vaughan4b0296d18849 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 command-d, and friends with hands may find that it is also dead to use docker run-d to start the container.
In fact, what we need to understand here is the running mechanism of the container. If the Docker container runs in the background, there must be a foreground process. Here, if we let the container have a foreground program to run, we can survive after-d startup of the container.
[root@localhost ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc600c4519fc8 centos "/ bin/bash" 3 hours ago Exited (0) 4 minutes ago pensive_jackson5a7a0d694651 busybox "sh" 21 hours ago Exited (0) 21 hours ago hungry_vaughan4b0296d18849 hello-world "/ hello" 47 hours ago Exited (0) ) 47 hours ago hopeful_ root@localhost [root @ localhost ~] # docker run-d centos / bin/bash-c "nohup ping-I 1000 www.baidu.com" 8aa19c9604382bc019797ccda831ae1bcebd81d86380b6040d636e03000b440a [root@localhost ~] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8aa19c960438 centos "/ bin/bash-c 'nohup …" 2 seconds ago Up 2 seconds adoring_wingc600c4519fc8 centos "/ bin/bash" 3 hours ago Exited (0) 5 minutes ago pensive_jackson5a7a0d694651 busybox "sh" 21 hours ago Exited (0) 21 hours ago hungry_vaughan4b0296d18849 hello-world "/ hello" 47 hours ago Exited (0) 47 hours ago hopeful_yonath
I use nohup here to run a Baidu process that ping every 1000 seconds. In addition, 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, you enter the container and type exit to exit, it will still terminate the container. Please keep in mind.
Ctrl+P+Q is still my best use.
Thank you for reading! This is the end of the article on "how to exit the container without closing the container in Docker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.