Docker container in detached and attached mode

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 
$ docker container ls

I hope this was useful for you and let’s see what’s next?

Greetings,

Thomas

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: