Using Docker Commands - Cheatsheet

Posted by : at

Category : docker

Ads by Google

Docker Commands Cheatsheet

To pull a docker image from the docker hub, we can use the command:

$ docker pull <image-name:tag>

To run that image, we can use the command :

$ docker run <image-name:tag> or $ docker run <image-id>

To list down all the images in our system, we can give the command :

$ docker images

To list down all the running containers, we can use the command :

$ docker ps

To list down all the containers ( even if they are not running ) :

$ docker ps -a

Creating a Dockerfile

Docker file - It contains instructions for building a docker image. Instructions contain various keywords.

FROM -> This keyword indicates the base image from which the container is built. RUN -> This keyword indicates the command that needs to be executed on the image.

Command to build an image:

$ docker build -t [image-name]:tag

eg. $ docker build -t gamershub:1.0

Command to Run the newly built image :

$ docker run --name "container-name" -p <host port>:<container port><image_name:tag>


$ docker run --name "ubuntutomcat7" -p 8080:8080 gamershub:1.0

Start / Stop Containers

  • We can start / stop containers by just running a command from the terminal
  • We need to specify the container id as parameter

To list down all the containers and their ID’s, use :

$ docker ps -a

To start the container, use the command :

$ docker start <container id>

To stop the container, use the command :

$ docker stop <container id>

To remove the container, use the below command after stopping the container

$ docker rm <container name>

To delete an image, we can use :

$ docker rmi <image id>
$ docker rmi <repo:tag>

To show all containers

$ docker ps -aq

To stop all containers

$ docker stop $(docker ps -aq)

To remove all containers

$ docker rm $(docker ps -aq)

To remove all images

$ docker rmi $(docker images -q)

To build image using dockerfile

$ docker build --no-cache -t ubuntu-py3 .

To run image

$ docker run -i -t ubuntu-py3 /bin/bash

Ads by Google