Attaching to Containers Using the attach Command
In the previous exercise, you saw how to use the docker exec
command to spin up a new shell session in a running container instance in which to execute commands. The docker exec
command is very good for quickly gaining access to a containerized instance for debugging, troubleshooting, and understanding the context the container is running in.
However, as covered earlier in the chapter, Docker containers run as per the life of the primary process running inside the container. When this process exits, the container will stop. If you wanted to access the primary process inside the container directly (as opposed to a secondary shell session), then Docker provides the docker attach
command to attach to the primary running process inside the container.
When using docker attach
, you are gaining access to the primary process running in the container. If this process is interactive, such as a Bash or Bourne shell session, you will be...