Docker Fundamentals - Container Lifecycle

Detaching and Attaching


Detaching and Attaching

Start a container with a command like this one:

$ docker conatiner run --name c1 -it alpine:latest sh

where c1 is the name given to the new container and alpine:latest is the name and tag of the image you wish to use. You should see / # at the prompt, indicating that you are attached to the container.

-it allows you to easily detach the container later by pressing ctrl+p+ctrl+q. If you instead use -itd the container will initialize unattached.

You can re-attach to a running container by entering $ docker container attach [container name]