Docker Tips and Tricks

In this article I will share some of the docker commands which I use at times. May be it can help you as well.

1) List all the containers including those are not running, by default only running containers are listed.

#docker ps -a

2) Delete all stopped containers.

$ docker rm $(docker ps -a -q)

3) IP address of all running containers.

$docker inspect $(docker ps -q) | grep IPAddress | cut -d ‘”‘ -f 4

4) If you want to list IP address of one of the container.

#docker inspect -f ‘{{ .NetworkSettings.IPAddress }}’ “container ID”

5) If you want to get into a container, use “docker exec” command. You can treat this as a replacement for “sshd” or “nsenter”.

$docker exec -ti “container ID” /bin/bash

6) Stop all running containers.

$docker stop $(docker ps -a -q)

7) To delete all existing docker images.

$docker rmi $(docker images -q -a)

8) To examine the logs of a container, use docker logs command with -f option which follows log output and continues streaming the new output from the container’s STDOUT and STDERR.:

$docker logs -f “Container ID”

9) Get the ID of last ran container.

$docker ps -a -q -l –no-trunc=true

10) Most of the time we want to exec into the container we just ran.

#docker exec -ti ( docker ps -a -q -l) /bin/bash

11) To list out the environment variables of an image

#docker run env

Digiprove sealCopyright secured by Digiprove © 2017 Humble Chirammal

Leave a Reply

Your email address will not be published. Required fields are marked *