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:
- Start the container in a detached and interactive mode and give the container the name demo.
$ 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?
PS: You can try out Cloud Foundry Apps or Kubernetes on IBM Cloud. By the way, you can use the IBM Cloud for free, if you simply create an IBM Lite account. Here you only need an e-mail address.
#Docker, #Container, #Attach, #Detach, #Interactive
Leave a Reply