Docker Cheatsheet

Docker Cheatsheet

Installation of Docker

  1. Remove any docker file running on the system using the below command,

    sudo apt-get remove docker docker-engine docker.io

  2. Update the package database,

    sudo apt-get update

  3. Install docker using the below command,

    sudo apt install docker.io

  4. Install all dependency packages,

    sudo snap install docker

  5. You can check the version of docker installed using this command,

    docker --version

  6. To check the docker installation is done correctly you can run the below command,

    sudo docker run hello-world

Working with images

  • docker images - List all images on the system

  • docker build . -t <image_name> <path> - Build an image from a Dockerfile in the specified path

  • docker push <image_name> - Push an image to a registry(docker-hub)

  • docker pull <image_name> - Pull an image from a registry(docker-hub)

  • docker rmi <image_name> - Remove an image

  • docker image prune - Remove all unused image

Working with containers

  • docker run -d <image-name> - Create and start a container based on the specified image

  • docker start <container-id> - Start a stopped container

  • docker stop <container-id> - Stop a running container

  • docker kill <container-id> - To kill the container

  • docker rm <container-id> - Remove a container

  • docker ps - List all running containers

  • docker ps -a - List all containers (running and stopped)

Working with volumes

  • docker volume create <volume-name> - Create a named volume

  • docker volume ls - List all named volumes

  • docker volume rm <volume-name> - Remove a named volume

Docker commands

  • docker exec <container-id> <command> - Run a command inside a running container

  • docker inspect <image-or-container> - Show detailed information about an image or container

  • docker logs <container-id> - Show the logs of a running container

  • docker login - Login to a Docker registry

  • docker logout - Logout from a Docker registry

These are some Docker commands which are used by me in day-to-day tasks.

Thank you!!