How do you attach and detach from Docker's process?

Better Stack Team
Updated on April 13, 2023

To attach to a running Docker container's process, you can use the docker attach command. This command attaches your terminal to the running process of the container, allowing you to view its output and send commands to it.

The basic syntax for docker attach is:

 
docker attach <container-name-or-id>

For example, to attach to a container named my-container, you would run:

 
docker attach my-container

To detach from the container without stopping it, you can press the Ctrl + P and Ctrl + Q keys together. This will detach your terminal from the container's process and return you to the host machine's command prompt.

To detach from the container and stop it at the same time, you can use the docker stop command. The basic syntax for docker stop is:

 
docker stop <container-name-or-id>

For example, to stop the container named my-container, you would run:

 
docker stop my-container

Note that stopping the container will also detach your terminal from the container's process. If you want to detach without stopping the container, you should use the Ctrl + P and Ctrl + Q key combinations.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack