Ways to enter the Docker container

Source: Internet
Author: User


How to log in to a container
SSH Login
third-party tools (Nsenter, Nsinit)                                                                                                                      Tools provided by Docker (Attach, exec)
Advantages
In line with the usual login server habits, no additional learning Quick and easy to use Quick and easy to use
Disadvantages Secret Key management SSH upgrade monitoring Need to learn third party tools using rules Docker host root permissions Using the Attach login container, exit exits the container Docker host root permissions same screen
Applicable scope
Applicable docker host login to container internal Telnet to the container Suitable for Docker host login to container interior Suitable for Docker host login to container interior

SSH
How to use: SSH user @ip address-p port
General SSH Login to go 22 ports, but in Docker Bridge network mode using NAT to do port mapping, ports need special annotations
Applicable scope: Docker host Internal login container, external terminal Direct login container
Advantages: To meet the administrator, developers login server habits, do not need to do additional learning
Disadvantage: 1. Secret Key Management If you write a secret key to a mirror, you need to recreate the mirror when you need to update the secret key, deploy, restart the container, although this step is cumbersome, but personally think it is safe. If you write a secret key to a volume, you first have to ensure that the container does not have write permission on the volume, otherwise there is a risk that the secret key will be tampered with. 2.SSH upgrade or patch SSH has a vulnerability or version upgrade, you need to patch or upgrade each containerDocker Attach How to use: Docker attach [container name]Scope of application:Docker Host Internal Login containerAdvantages:Fast and convenientDisadvantage :1.exit exit directly after the container 2. Multi-screen Sync this is equivalent to a maximum of one terminal connection container at the same time



Docker exec
How to use
: Docker exec-it [container name] [command]
Applicable scope: Docker Host Internal login container
Advantages: Quick and convenient
Disadvantage: External terminals cannot use this method to log in to containers
Introduction to Using Parameters
-I,--interactive Keep STDIN Open even if not attached ———— interaction
-T,--tty Allocate a pseudo-tty ———— distribution pseudo terminal
In general, you use the-it command, and if you only use the-I command alone
The-i parameter does not produce a pseudo terminal, but will have the correct return to use-it, similar to our normal operation of the console interface. And it's not going to be like the attach way because exiting, causing the entire container to exit. This method can be used in lieu of ssh or nsenter, Nsinit mode, in the container to operate.
Installation of the Nsenter tool Nsenter tool: Wget https://www.kernel.org/pub/linux/utils/util-linux/v2.28/util-linux-2. 28.tar.gz TAR-XZVF util-linux-2.28.tar.gz CD util-linux-2.28
./configure--without-ncurses make Nsenter CP nsenter/usr/local/bin
After the installation is complete, use the NSENTER-HELP command to view, you can see the use of methods and parameters to prove that the installation was successful.
Log on using the Nsenter command Docker container when you use Nsenter to log in to Docker container, the first 6 parameters are generally used (I think the other people write, thinking about why, may use the first 6 parameters can cover the network, disk, process management operating system basic information, I tasted Try to log in to the container using only one or more of the parameters, but the operating system features are limited, such as inability to use the network configuration feature.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.