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

How does the Linux system enter the docker container

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

The editor today takes you to understand how the Linux system enters the docker container. The knowledge points in the article are introduced in great detail. Friends who think it is helpful can browse the content of the article with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's follow the editor to learn more about "how to enter the docker container in Linux system".

One of the problems we face when we install and run docker is how to get inside docker? There are many ways to enter docker using ssh login, third-party tools (nsenter, nsinit), tools provided by docker (attach, exec), and so on.

How to log in to the container ssh login third-party tools (nsenter, nsinit) the advantages of the tools provided by docker (attach, exec) are in line with the usual habit of logging in to the server, and there is no need to learn to use convenient and fast use ssh upgrade monitoring needs to learn third-party tools to use rules docker host root permissions to log on to the container using attach Exit exit container docker host root permissions same screen applicable scope docker host login to container internal remote login container applicable docker host login to container interior applicable docker host login to container internal SSH usage: ssh user @ IP address-p port generally ssh login takes port 22, but in docker bridge network mode uses NAT for port mapping Port needs to be specially marked applicable scope: docker host internal login container, external terminal direct login container advantages: in line with the administrator, developers login server habits, no need for additional learning disadvantages: 1. Secret key management

If you write the key to the image, you need to remake the image, deploy and restart the container when you need to update the key. Although this step is tedious, I think it is safe. If you write the key to a volume, you must first ensure that the container does not have write permission for the volume, otherwise there is a risk that the key will be tampered with.

2.ssh upgrade or patch

When there are vulnerabilities or version upgrades in ssh, you need to patch or upgrade each container.

Docker attach

Usage: docker attach [container name]

Scope of application: docker host internal login container

Advantages: fast and convenient

Disadvantages: exit the container directly after 1.exit

\ 2. Multi-screen synchronization, which means that at most one terminal can connect to the container at a time.

Docker exec usage: docker exec-it [container name] [command] scope of application: docker host internal login container advantages: fast and convenient disadvantages: external terminals can not use this method login container use parameters introduction:-I,-interactive Keep STDIN open even if not attached-interaction-t,-tty Allocate a pseudo-TTY---- assignment pseudo-terminals generally use-it this combination command If you can only use the-I command-I parameter alone, it will not produce a pseudo terminal, but it will return correctly.

When using-it, it is similar to how we normally operate the console interface. And it will not cause the entire container to exit as a result of exiting in the attach way. This method can operate in the container instead of ssh or nsenter or nsinit.

Nsenter tool

Installation of nsenter tools:

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 check, you can see that the usage and parameters prove that the installation is successful.

Use the nsenter command to log in to the docker container

When using nsenter to log in to the docker container, you usually use the first six parameters (I see what others have written. After thinking about the reason, you may use the first six parameters to cover the basic information of the network, disk, and process management operating system. I try to log in to the container using only one or more of these parameters, but there are restrictions on the use of operating system functions, such as the inability to use network configuration features, etc.).

Thank you for your reading, the above is the whole content of "how the Linux system enters the docker container", learn friends to hurry up to operate it. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!

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

Development

Wechat

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

12
Report