DEV Community

Cover image for Docker Cheatsheet: Essential Commands You Need to Know
Enodi Audu
Enodi Audu

Posted on

Docker Cheatsheet: Essential Commands You Need to Know

Docker has become a go-to tool for developers, simplifying the process of creating, deploying, and running applications using containers. Here’s a handy cheat sheet of essential Docker commands to help you navigate Docker like a pro.

1. Docker Basics

  • docker --version This shows you the current version of Docker you have installed.
  docker --version
Enter fullscreen mode Exit fullscreen mode
  • docker info This will list detailed information about your Docker setup.
  docker info
Enter fullscreen mode Exit fullscreen mode

2. Working with Images

  • docker pull [image] This command downloads an image from the Docker Hub.
  docker pull [image_name]
Enter fullscreen mode Exit fullscreen mode
  • docker images List all the images you have on your system.
  docker images
Enter fullscreen mode Exit fullscreen mode
  • docker rmi [image] Remove an image from your system.
  docker rmi [image_name] e.g docker rmi postgres
Enter fullscreen mode Exit fullscreen mode

3. Managing Containers

  • docker run [image] Create and start a new container from an image.
  docker run [image_name]
Enter fullscreen mode Exit fullscreen mode
  • docker ps List all running containers.
  docker ps
Enter fullscreen mode Exit fullscreen mode
  • docker ps -a List all containers, including those that are stopped.
  docker ps -a
Enter fullscreen mode Exit fullscreen mode
  • docker stop [container_id] Stop a running container.
  docker stop [container_id]
Enter fullscreen mode Exit fullscreen mode
  • docker start [container_id] Start a stopped container.
  docker start [container_id]
Enter fullscreen mode Exit fullscreen mode
  • docker rm [container_id] Remove a stopped container.
  docker rm [container_id]
Enter fullscreen mode Exit fullscreen mode

4. Accessing Containers

  • docker exec -it [container_id] /bin/bash Access a running container with an interactive shell.
  docker exec -it [container_id] /bin/bash
Enter fullscreen mode Exit fullscreen mode

5. Building Images

  • docker build -t [name:tag] [path] Build a new image from a Dockerfile.
  docker build -t [name:tag] [path] e.g docker build -t app:latest .
Enter fullscreen mode Exit fullscreen mode

6. Docker Networks

  • docker network ls List all networks.
  docker network ls
Enter fullscreen mode Exit fullscreen mode
  • docker network create [network_name] Create a new network.
  docker network create [network_name] e.g docker network create 
  backend_default
Enter fullscreen mode Exit fullscreen mode
  • docker network rm [network_name] Remove a network.
  docker network rm [network_name]
Enter fullscreen mode Exit fullscreen mode

7. Docker Volumes

  • docker volume ls List all volumes.
  docker volume ls
Enter fullscreen mode Exit fullscreen mode
  • docker volume create [volume_name] Create a new volume.
  docker volume create [volume_name] e.g docker volume create 
  backend_pgdata
Enter fullscreen mode Exit fullscreen mode
  • docker volume rm [volume_name] Remove a volume.
  docker volume rm [volume_name]
Enter fullscreen mode Exit fullscreen mode

8. Docker Compose

  • docker-compose up Start and run your Docker Compose services.
  docker-compose up
Enter fullscreen mode Exit fullscreen mode
  • docker-compose down Stop and remove Docker Compose services.
  docker-compose down
Enter fullscreen mode Exit fullscreen mode
  • docker-compose build Build or rebuild services.
  docker-compose build
Enter fullscreen mode Exit fullscreen mode

This cheatsheet covers the most essential Docker commands to get you started. Whether you’re managing images, containers, networks, or volumes, these commands will help you streamline your workflow and make the most out of Docker.

If you found this article helpful, please like and share it. Comment below with any other Docker commands or tips you’ve found useful. Happy coding :)

Top comments (0)