Docker: The most important and frequently used commands

In this article i am expected to give you few commands that are frequently required and used when building, shipping and running docker images and containers.

 

Checking the docker version

docker -v     OR    docker --version

 

Get currently running containers (only the active containers)

docker ps

 

Get all containers ( all running + stopped)

docker ps -a

 

Get a list of images available

docker images

 

Removing image 

docker rmi <image-id>

 

Start/run a container

docker run <image-name>

 

Start the Stopped Container

docker start <container-id>

 

stop running container

docker stop <container-id>

 

Get the last created container

docker ps -l

 

Go to the bash mode of the running container

docker exec -it <running-container-name> bash

 

Get IP Address of the docker container

docker inspect <container-id>

 

Show docker disk usage

This will display the disk usage of the docker.

docker system df

https://docs.docker.com/engine/reference/commandline/system_df/

 

See a list of volumes

docker volume ls

 

Remove a volume

docker volume rm  <volume-name>

 

Prune volumes

Volumes can be used by one or more containers, and take up space on the Docker host. Volumes are never removed automatically, because to do so could destroy data.

$ docker volume prune

WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y

By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag.

By default, all unused volumes are removed. You can limit the scope using the --filter flag. For instance, the following command only removes volumes which are not labelled with the keep label:

$ docker volume prune --filter"label!=keep"

 

 

2 thoughts on “Docker: The most important and frequently used commands

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s