How to detach from a container without stopping it?

Better Stack Team
Updated on April 14, 2023

To detach from a container without stopping it, you can use the CTRL + P followed by CTRL + Q key sequence while attached to the container using the docker attach command or by running the container in attached mode using the -it flag.

For example, if you are attached to a running container using the docker attach command, you can use the following key sequence to detach from the container:

Alternatively, you can start a container in detached mode using the -d flag and then attach to it later using the docker attach command. To start a container in detached mode, use the following command:

 
docker run -d <image-name>

Replace <image-name> with the name of the Docker image you want to run. This command starts the container in the background and returns its container ID. You can then attach to the container later using the following command:

 
docker attach <container-id>

Replace <container-id> with the container ID you obtained when you started the container in detached mode. Once attached to the container, you can use the CTRL + P followed by CTRL + Q key sequence to detach from the container without stopping it.

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