Get the App
SLTechnology News&Howtos  ›  Servers  › 

How does docker enter a running container

Shulou Source: shulou.com Published: 2022-06-03 00:45:51 09月23日 Update

Today, what the editor shares with you is how docker enters the running container. I believe many people don't know much about it. In order to make you understand better, I summed up the following contents for you. Let's look down together. I'm sure you'll get something.

There are three ways we want to enter the container we are using. They are:

1) docker attach [Container name]: attach is similar to VNC, and the operation is displayed in each container interface. Therefore, all operations entering the container are displayed synchronously, but when exit exits the container, the container also stops, so this method is not recommended.

2) docker exec-it [container name / id]: enter the container after executing a single command, which is not recommended, although the container will not stop after exit exits.

3) nsenter-t [container pid]-m-u-I-n-p: enter the container in this way, provided that you must know the PID number of the container before it can be executed. You can obtain the PID number of the container through docker inspect-f {{. State. Pid}} [container name].

Expansion: about entering containers

When using the-d parameter, the container will enter the background after startup. There are many ways to enter the container to operate, including using the docker attach command or the nsenter command.

Use docker attach to enter the container

1.docker attach allows us to enter the background process.

2.-sig-proxy=false does not use the container to forward signals, which allows us to use ctrl-c to exit, execute dockerps view and run in the background.

But using the attach command is sometimes inconvenient. When multiple windows are attach to the same container at the same time, all windows are displayed synchronously. When one window is blocked by a command, other windows cannot perform the operation.

You can also execute docker exec to enter the running container

Docker exec-it container ID/ name / bin/bash

The above command returns a command interface, and exec stands for running the command directly in the container

On how to enter the running container of docker is shared here, I hope that the above content can have a certain reference value for you, you can learn to apply. If you like this article, you might as well share it for more people to see.

Tags: Container command run name background mode content method time interface recommendation learning for application representative value signal premise parameter can be passed at the same time backward Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei macOS Redmi Xiaomi