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.

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