This is a very short blog post about the usage of a Docker container in detached and attached mode. Some times participants in workshops want to reconnect to a docker container, because they closed their terminal session with the container which was in an interactive mode and they want to reconnect to their exiting container image.
Here is a short example for detached and attached mode that uses the tsuedbroecker/cns-workshop-tools:v1 container image:
$ docker run -dit --name demo "tsuedbroecker/cns-workshop-tools:v1" /bin/bash
- Find the container by search in the stopped and running container with ps.
$ docker ps -a | grep tsuedbroecker/cns-workshop-tools:v1
- Attach to the container. In this case I use the container name demo. When you use the command exit in the terminal’s standard input/output, the container will be stopped.
$ docker attach demo
- Remove the stopped container
$ docker rm demo
- Verify the container is deleted, by listing the containers.
$ docker container ls
I hope this was useful for you and let’s see what’s next?
#Docker, #Container, #Attach, #Detach, #Interactive