Docker Commands Cheatsheet

student cheating during an exam
Docker Cheatsheet


All Docker Commands in one place


  • docker image ls
  • docker image pull hello-world
  • docker version
  • docker image inspect imagename
  • docker image history imagename
  • docker image run hello-world
  • docker image build -t imageName .
  • docker image history imageName
  • docker image rm imageName
  • docker image tag imageName jonesjalapatgithub/imageName
  • docker login
  • docker image push jonesjalapatgithub/imageName
  • docker image prune


  • docker container create hello-world –name hello
  • docker container ls -a
  • docker container start hello
  • docker container stop hello
  • docker container run –name hello hello-world
  • docker container inspect hello
  • docker container logs hello
  • docker container run –name hello –rm hello-world
  • docker container run –name ubuntu –rm ubuntu date
  • docker container run –name ubuntu -it ubuntu
  • docker container attach ubuntu
  • docker container exec -it ubuntu bash
  • docker container rm ubuntu –force
  • docker container run -itd –name ubuntu ubuntu 
  • docker container run -itd –name mysql -e MYSQL_ROOT_PASSWORD=root mysql
  • docker container run -itd –name nginx nginx
  • docker container run -itd -p 8081:80 –name nginx nginx


  • docker volume prune
  • docker volume ls
  • docker volume create volumeName
  • docker network inspect bridge
  • docker network create –subnet mybridge
  • docker network ls
  • docker network connect mybridge container
  • docker network disconnect bridge container
  • docker container run –name httpd-1 –network host -itd httpd


Some Facts about Docker

  • By-default Docker runs with 1GB memory
  • Containers are immutable
  • Container shares OS memory – OS Virtualisation
  • Docker Inc started by Solomon Hykes
  • Docker image made of many layers, any update adds new layers
  • Docker uses Union FS for implementing Layered docker images


Create a simple docker File for running a webapp

  • FROM httpd
  • COPY ./index.html /usr/local/apache2/htdocs/
  • EXPOSE 80
  • CMD apachectl -D FOREGROUND

Create a simple docker File for running a Java

  • FROM openjdk:8
  • WORKDIR /src
  • COPY ./ .
  • RUN javac ./
  • CMD java Test

Multi-Stages Build

Create a multi Stage docker File for running a Java

# build
FROM openjdk:8 AS Stage1
RUN javac

# execution
FROM alpine
RUN apk add openjdk8-jre
COPY --from=Stage1 /src/Test.class .
CMD java Test

Create a multi Stage docker File for running Angular

FROM node:14.15 AS Stage1

RUN npm install -g @angular/cli
COPY . .
RUN ng build --prod

FROM httpd
COPY --from=Stage1  /src/dist/app1/ /usr/local/apache2/htdocs/

Run a MongoDB Container with Volumes

/var/lib/docker/volumes – Volumes location

  • docker container run -itd –name mysql2 -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v myvolume:/var/lib/mysql mysql
  • docker container run -itd –name bindmount -p 8080:80 -v /Users/jonesalapat/jones/work/docker/app1/app3/:/usr/local/apache2/htdocs httpd

Custom Network

Container have address starting from 172.17.0.x, CIDR for Docker container :-

docker container run -itd –name c3 –network mybridge alpine : RUN a container on your network


Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

First APP
Second APP

version: '3'

    build: ./FirstAPP
      - '3000:3000'
    build: ./SecondAPP
      - '4000:4000'

The command to up docker compose file

  •  docker-compose up -d
  •  docker-compose down


A Docker Swarm is a group of virtual machines running the Docker and that have been configured to join together in a cluster.
ocker works to maintain that desired state. For instance, if a worker node becomes unavailable, Docker schedules that node’s tasks on other nodes. A task is a running container which is part of a swarm service and managed by a swarm manager, as opposed to a standalone container. These act similar to Kubernetes/ ECS etc.

error: Content is protected !!
Scroll to Top