Some useful docker Commands for handling images and containers


With reference to the past lab sessions let us recap the below docker commands for reference.

Commands for images and containers handling:

1. How to list docker images:

$ sudo docker images

2. How to check the images status:

$ sudo docker ps -a

3. How to tag a docker image:

$ sudo docker tag <image id> < image name >

Ex: sudo docker tag 8de083612fef ubuntu-testbox1

4. How to list the container ids:

$ sudo docker pa -aq

5. How to remove all containers:

$ sudo docker containers prune

It removes all the containers on the current docker host machine

6. How to remove a docker image:

$sudo docker rmi image <image id>


sudo docker rmi image 6ad733544a63

7. How to run a dockerfile from the current directory:

$ sudo docker build -t ubuntu-vmbox .

Note: You need to make sure there is a dockerfile in the pwd.

8. How to run a container as interactive in a terminal mode:

$ sudo docker run -i -t ubuntu-vmbox /bin/bash

Note: Ubuntu-vmcbox is your image repository name.

9. How to see a history of a docker image:

$ sudo docker history hello-world

Note: hello-world is a docker image.

10. How to see the docker information:

$ sudo docker info

11. How to check the docker services status:

$ sudo service docker status

12. How to start a container :

$ sudo docker start  d10ad2bd62f7

13. How to stop a container :

$ sudo docker stop d10ad2bd62f7

14. How to attach  a container  into interactive terminal mode:
$ sudo docker attach d10ad2bd62f7

Note: The container comes into terminal interactive mode.

15. How to pause a container:
$ sudo docker pause 155f4b0764b1

16. How to unpause a container:
$ sudo docker unpause 155f4b0764b1

17. How to remove a single container:

$ sudo docker rm <container id>

Example: sudo docker rm 1dd55efde43f

Note: You can use prune command to remove all the containers as mentioned in the above questions.


Leave a Reply

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

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

Facebook photo

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

Connecting to %s