Tags

Lets assume that you’ve created or downloaded some docker images. But in this tutorial, we are going to use the ubuntu-xenial image.

$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
ubuntu-xenial               latest              1d4b614305f6        23 minutes ago      859.8 MB
friendlyhello               latest              bf391a773695        18 hours ago        194.6 MB
python                      2.7-slim            1c7128a655f6        2 weeks ago         182.8 MB
mysql                       5.5                 c0fb485deb70        5 weeks ago         256 MB
truthadjustr/myng2          latest              f76b7a86e3b1        6 weeks ago         852.4 MB
hello-world                 latest              48b5124b2768        4 months ago        1.84 kB
ibmcom/cloudant-developer   latest              fb798da3ab5d        11 months ago       1.162 GB

Next, lets see if there are running container.

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

We can see that there are no active running container. Let’s display all containers by running the command docker ps -a

## List all running/stopped containers
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
871e7dfd063c        ubuntu-xenial       "bash"              46 seconds ago      Exited (0) 6 seconds ago                       vigorous_johnson

Yay! there is one existing container available. Let’s use it.
But if ever there is no container found then we need to run the command docker run -it ubuntu-xenial bash first!

Moving forward, lets rename the existing container name.

## Rename from vigorous_johnson to ubuntu_xenial
$ docker rename 871e ubuntu_xenial

So renaming is done let’s verify it. It should be ubuntu_xenial now.

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
871e7dfd063c        ubuntu-xenial       "bash"              46 seconds ago      Exited (0) 6 seconds ago                       ubuntu_xenial

Next, we can see that the container(ubuntu_xenial) was exited then lets start it..

$ docker start ubuntu_xenial
ubuntu_xenial

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
871e7dfd063c        ubuntu-xenial       "bash"              46 seconds ago      Up to 5 seconds                                ubuntu_xenial

So the container ubuntu_xenial is started..lets execute it.

$ docker exec -it ubuntu_xenial bash

TAKE NOTE: if we run the image again it will create another container.

$ docker run -it ubuntu-xenial bash
## After running docker run run there are
## now two containers created from image ubuntu-xenial.
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
6409eda3b5d6        ubuntu-xenial       "bash"              20 minutes ago      Exited (0) 8 minutes ago                       agitated_shannon
871e7dfd063c        ubuntu-xenial       "bash"              22 minutes ago      Up 20 minutes                                  ubuntu_xenial

So, it is recommended to just re-use one container otherwise there is a reason to do it.

Advertisements