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

Better Stack Team
Updated on October 5, 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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github