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 use
docker 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. - use
docker attach container idEntering the executing container will not start a new terminal,When exiting a container, it will cause the container to stop.

