In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "common commands for docker to enter the container". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Use docker attach to enter
Docker provides the attach command to enter the Docker container. We create a guarded Docker container and then use the docker attach command to enter the container.
$sudo docker run-itd ubuntu:14.04 / bin/bash
Then we use docker ps to see the container information, and then we use docker attach to enter the container
$sudo docker attach 44fc0f0582d9
You can see that we have entered the container.
But there is a problem with using this command. When multiple windows enter the container at the same time using this command, all windows are displayed synchronously. If one window is blocked, the other windows can no longer operate. Therefore, the docker attach command is not suitable for production environments and can be used when developing your own applications.
Use nsenter to enter the Docker container
Use nsenter to enter the Docker container. After knowing what nsenter is, the system installs the nsenter we need into the host by default. The specific installation commands are as follows:
$wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz$ tar-xzvf util-linux-2.24.tar.gz$ cd util-linux-2.24/$. / configure-- without-ncurses$ make nsenter$ sudo cp nsenter / usr/local/bin
After you have installed nsenter, you can check the use of this command. Nsenter can access the namespace of another process. So to connect to a container, we also need to get the PID of the first process of the container. You can use the docker inspect command to get the PID.
$sudo docker inspect-help
The inspect command can display information about an image or container at a hierarchical level. For example, we currently have a running container, and we can use docker inspect to view the details of the container.
$sudo docker inspect 44fc0f0582d9
If you want to display the first PID of the container, you can use the following ways
$sudo docker inspect-f {{.State.Pid}} 44fc0f0582d9
After getting the process PID, we can use the nsenter command to access the container.
Sudo nsenter-- target 3326-- mount-- uts-- ipc-- net-- pid$ sudo nsenter-- target 3326-- mount-- uts-- ipc-- net-- pid
3326 of them are the PID of the process just obtained.
Use docker exec to enter
Docker also provides a new command exec to enter the container after version 1.3.x, which is relatively simple.
$sudo docker exec-help
Next we use this command to enter a container that is already running
This is the end of the $sudo docker ps$ sudo docker exec-it 775c7c9ee1e1 / bin/bash "common commands for docker to enter the container". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.