Docker Commands Cheat Sheet

Docker has revolutionized the way applications are packaged, distributed, and deployed. It provides a lightweight and efficient solution for containerization, enabling developers to build and run applications consistently across different environments. To make the most out of Docker, it’s essential to be familiar with its commands and their usage. In this article, we present a Docker commands cheat sheet that can help developers navigate their Docker workflows effectively.

Note: This cheat sheet assumes that Docker is installed and properly configured on your system.

  1. Docker Image Commands:
  • docker images: List all available Docker images on the local machine.
  • docker pull <image>: Download a Docker image from a registry, such as Docker Hub.
  • docker build -t <tag> <directory>: Build a Docker image using a Dockerfile located in the specified directory.
  • docker push <image>: Push a Docker image to a registry, making it available for others to download.
  1. Docker Container Commands:
  • docker run <image>: Create and start a new container from a Docker image.
  • docker ps: List all running containers.
  • docker ps -a: List all containers, including those that are not running.
  • docker start <container>: Start a stopped container.
  • docker stop <container>: Stop a running container.
  • docker restart <container>: Restart a running container.
  • docker rm <container>: Remove a stopped container.
  • docker exec -it <container> <command>: Execute a command within a running container.
  1. Docker Network Commands:
  • docker network ls: List all Docker networks.
  • docker network create <network>: Create a new Docker network.
  • docker network inspect <network>: Display detailed information about a Docker network.
  1. Docker Volume Commands:
  • docker volume ls: List all Docker volumes.
  • docker volume create <volume>: Create a new Docker volume.
  • docker volume inspect <volume>: Display detailed information about a Docker volume.
  1. Docker Compose Commands:
  • docker-compose up: Create and start containers defined in a Docker Compose file.
  • docker-compose down: Stop and remove containers defined in a Docker Compose file.
  1. Docker Registry Commands:
  • docker login: Log in to a Docker registry.
  • docker logout: Log out from a Docker registry.
  • docker search <term>: Search for Docker images on a registry.
  1. Docker System Commands:
  • docker info: Display detailed information about the Docker system.
  • docker version: Show the Docker version information.
  • docker system prune: Remove unused Docker resources, such as stopped containers and unused images.

Conclusion

This Docker commands cheat sheet provides a handy reference for developers working with Docker. By familiarizing themselves with these commands and their usage, developers can efficiently build, manage, and deploy Docker containers. Remember to refer to Docker’s official documentation for more in-depth explanations and advanced usage of these commands. With this cheat sheet, developers can streamline their Docker workflows and leverage the power of containerization to enhance their application development and deployment processes.