Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method for docker to enter the container

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

How does docker enter the container? Several common ways to enter the docker container are to use docker attach;, use SSH;, use nsenter;, and use exec.

1.docker attach enters 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 use docker ps to view the container information, and then use docker attach to enter the container

$sudo docker attach 44fc0f0582d9

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. For this reason, the docker attach command is not suitable for production environments and can be used when developing your own applications.

two。 Use SSH to enter the Docker container

Installing SSH Server in the image (or container) ensures that multiple people enter the container without interference with each other. It is believed that everyone will do the same in the current production environment (without using Docker).

3. Use nsenter to enter the Docker container

There is also a more convenient way to enter the Docker container using nsenter. By default, the system installs the nsenter we need into the host.

If it is not installed, follow these steps to install it (note that it is the host, not the container or image).

$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

4. Use docker exec to enter the Docker container

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

$sudo docker ps$ sudo docker exec-it 775c7c9ee1e1 / bin/bash

As a senior professional cloud computing service provider and cloud security service provider in the industry, it is committed to providing cloud servers for Internet enterprise users and enterprise users in traditional industries. Its products have the characteristics and advantages of "security and stability, easy to use, high service availability, high performance-to-price ratio" and are designed to be customized for enterprises to meet the needs of rich and diversified application scenarios.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report