The difference between Docker attach and Docker exec

After the container starts and enters the background, you can use the Docker attach command or the Docker exec command to enter the container for operations.


1. attach command

attach is a command that comes with Docker. The format of the command is:
docker attach [OPTIONS] CONTAINER

2. exec command

From version 1.3 of Docker, Docker provides a more convenient tool exec command, which can directly execute arbitrary commands in the running container. The command format is:
docker exec [OPTIONS] CONTAINER COMMAND [ARG…]


3. Difference:

  • When multiple windows are attached to the same container, all windows will be displayed synchronously; when a window is blocked by a command, other windows cannot perform operations.
  • can usedocker exec -it public ID /bin/bashEnter the container and open a new bash terminal.When exiting the container terminal, it does not cause the container to stop.
  • usedocker attach container idEntering the executing container will not start a new terminal,When exiting a container, it will cause the container to stop.

Related Posts

[docker series] Build JDK and SpringBoot project mirror

I use the composition of the 2022 college entrance examination volume I to see the update of the Docker example of cloud native [Own hand, wonderful hand, common hand]

[docker series] Use non-root users to install and start docker (run in rootless mode)

docker-compose common commands and yml file writing

[Cloud Native-Docker] Quickly Build Daily Application Deployment

k8s binary installation and deployment (details)

OAI 5G core network installed and connected to gNB

gorm create and update advanced usage

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*