Docker cheat-sheet

Dhwarika JhaDhwarika Jha
2 min read

Docker Basic Command

  • To see all images present in your local.
  • docker images

  • To find out images in the docker hub.

    docker search <image_name>

  • To download an image from docker-hub to a local machine.

    docker pull <image_name>

  • To give a name to the container and run.

    docker run -it --name <container-name> <image_name> [-it interactive mode & direct to terminal]

  • To check, whether the service is starting or not.

    systemctl status docker / service docker status

  • To start the service.

    systemctl start docker / service docker start

  • To start/stop the container.

    docker start <container-name>

    docker stop <container-name>

  • To go inside the container.

    docker attach <container-name>

  • To see all the containers.

    docker ps -a

  • To see only running containers.

    docker ps

  • To delete the container.

    docker rm <container-name>

  • Exiting from the docker container.

    exit

  • To delete images.

    docker rmi <image-name/id>

    docker image rm <image-name/id>

  • Create an image from Container

    docker commit <container-name>

Docker Volume

  • To create a docker volume

    docker volume create <volume_name>

  • To see all created volumes

    docker volume ls

  • To delete volume

    docker volume rm <volume-name>

  • To remove all unused docker volumes

    docker volume prune

  • To get volume details

    docker volume inspect <volume-name>

  • To get container details

    docker inspect <container-name>

Docker Hub login

  • Login to registry

    docker login

  • Logout for registry

    docker logout

Builder Main Commands

Builder Main Commands

  • To create an image out of Dockerfile

    docker build . -t imagename

  • Manage containers

      docker create [options] IMAGE
        -a, --attach               # attach stdout/err
        -i, --interactive          # attach stdin (interactive)
        -t, --tty                  # pseudo-tty
            --name NAME            # name your image
        -p, --publish 5000:5000    # port map
            --expose 5432          # expose a port to linked containers
        -P, --publish-all          # publish all ports
            --link container:alias # linking
        -v, --volume `pwd`:/app    # mount (absolute paths needed)
        -e, --env NAME=hello       # env vars
    

Docker-compose

# docker-compose.yml
version: '2'

services:
  web:
    build:
    # build from Dockerfile
      context: ./Path
      dockerfile: Dockerfile
    ports:
     - "5000:5000"
    volumes:
     - .:/code
  redis:
    image: redis

Commands

  •   docker-compose start
      docker-compose stop
    
      docker-compose pause
      docker-compose unpause
    
      docker-compose ps
      docker-compose up
      docker-compose down
    

    Thank you for Reading

3
Subscribe to my newsletter

Read articles from Dhwarika Jha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dhwarika Jha
Dhwarika Jha