Docker Commands Cheat Sheet | Manage Docker Containers

What is Docker?

Docker is a platform for developers and sysadmins to develop, ship, and run applications in containers. Containers are lightweight, portable, and self-sufficient, which makes them an efficient way to package and distribute software.

Docker enables developers to package an application and its dependencies in a container, allowing it to run consistently across different environments. This helps to eliminate "works on my machine" issues and makes it easier to move applications between development, testing, and production environments.

Docker uses a containerization approach, which is an operating-system-level virtualization method for running multiple isolated systems on a single host. Containers are lightweight because they share the host operating system kernel and only include the libraries and settings required for the application to run.

Docker has a public registry called Docker Hub, where developers can store and distribute their images. Docker also includes a command-line tool that allows users to manage containers, images, and networks.

Docker is widely used in DevOps and cloud computing, it enables developers to quickly and easily create, deploy, and run applications in a variety of different environments, such as on-premises servers, private and public clouds, and hybrid environments.

What is a Docker Hub?

Docker Hub is a Container Image Library or App Containerization to create, manage and deliver containerized application at ease. It is a service provider by Docker to pull and push container images.

Docker Hub Container Image Library is a open source projects, independent software vendors for building, managing and distributing.

Create an account or Login to your Docker Hub @ https://hub.docker.com/

What is Docker Container?

Container is an instance of a Docker image. This represents single application, process, or service. It includes, application executable code, the runtime environment (such as .NET Core, Python, Java), system tools, settings. One can create multiple instances of a container from the same image

Docker Container Image: It is a package with all the dependencies and information required to create a container.

Dependencies include frameworks and the deployment and execution configuration that a container runtime uses.

Usually, an image derives from multiple base images that are layers stacked on top of each other to form the container's file system.

An image is immutable once it has been created.

Docker Build: Action of building a container image based on the information and context provided in the Dockerfile.

Docker Pull: Process of downloading a container image from a container registry.

Docker Push: Process of uploading a container image to a container registry.

Dockerfile: Dockerfiles enable you to create your own images. It is like a batch script. It refers to a text file that contains set of instructions on how to build a Docker image. The first line identifies the base image. The rest of the file includes the build actions.

Docker Commands Cheat Sheet
docker attach
• Description: Attach local standard input, output, and error streams to a running container
docker build
• Description: Build an image from a Dockerfile
docker commit
• Description: Create a new image from a container’s changes
docker cp
• Description: Copy files/folders between a container and the local filesystem
docker create
• Description: Create a new container
docker diff
• Description: Inspect changes to files or directories on a container's filesystem
docker events
• Description: Get real-time events from the server
docker exec
• Description: Run a command in a running container
docker export
• Description: Export a container’s filesystem as a tar archive
docker history
• Description: Show the history of an image
docker images
• Description: List images
docker import
• Description: Import the contents from a tarball to create a filesystem image
docker info
• Description: Display system-wide information
docker inspect
• Description: Return low-level information on Docker objects
docker kill
• Description: Kill one or more running containers
docker load
• Description: Load an image from a tar archive or STDIN
docker login
• Description: Log in to a Docker registry
docker logout
• Description: Log out from a Docker registry
docker logs
• Description: Fetch the logs of a container
docker network
• Description: Manage Docker networks
docker node
• Description: Manage Swarm nodes
docker pause
• Description: Pause all processes within one or more containers
docker plugin
• Description: Manage plugins
docker port
• Description: List port mappings or a specific mapping for the container
docker ps
• Description: List containers
docker pull
• Description: Pull an image or a repository from a registry
docker push
• Description: Push an image or a repository to a registry
docker rename
• Description: Rename a container
docker restart
• Description: Restart one or more containers
docker rm
• Description: Remove one or more containers
docker rmi
• Description: Remove one or more images
docker run
• Description: Run a command in a new container
docker save
• Description: Save one or more images to a tar archive (streamed to STDOUT by default)
docker search
• Description: Search the Docker Hub for images
docker service
• Description: Manage Docker services
docker start
• Description: Start one or more stopped containers
docker stats
• Description: Display a live stream of container(s) resource usage statistics
docker stop
• Description: Stop one or more running containers
docker swarm
• Description: Manage Swarm
docker tag
• Description: Tag an image to a repository
docker top
• Description: Display the running processes of a container
docker unpause
• Description: Unpause all processes within one or more containers
docker update
• Description: Update configuration of one or more containers
docker version
• Description: Show the Docker version information
docker volume
• Description: Manage Docker volumes
docker wait
• Description: Block until one or more containers stop, then print their exit codes
Docker Installation, Image Management & Setup Guide
Install Docker on Linux (YUM)
• Update Package Index: sudo yum -y update
• Install Docker: sudo yum install -y docker
• Description: Connect to your Linux server and install the latest version of Docker using the YUM package manager
Verify Docker Installation
• Check Version: docker --version (or docker -v / docker)
• Description: Returns both client and server release version numbers (major, minor, and patch) to ensure security and feature compatibility
Start Service & Configure Permissions
• Start Service: sudo service docker start
• Run Without Sudo: sudo usermod -a -G docker "user"
• Description: Start the daemon service and add your system user to the docker group to execute commands without sudo
Docker System Info
• Command: docker info
• Description: Display system-wide overview including active/stopped container counts, memory, storage utilization, and daemon configurations
Download & Run Docker Images
• Pull Image Syntax: docker pull <image_name> (e.g., docker pull nginx)
• Run Container Syntax: docker run --name <container_name> -d <image_name> (e.g., docker run --name nginxservice -d nginx)
• Description: Download official images from Docker Hub and run containers in background mode (-d) with custom names (--name)
Check Images & History
• List Images: docker images
• Image History Syntax: docker history <image_name> (e.g., docker history nginx)
• Description: Verify downloaded images on your system and view the layered build command history of an image
Container Health Check & Listing
• Running Containers: docker ps
• All Containers (All States): docker ps -a
• Description: View active container processes or inspect all instances regardless of their running status
Remove Images & Clean Up
• Remove Single Image: docker rmi <image_name> (e.g., docker rmi nginx)
• Remove All Images: docker rmi $(docker images -q)
• Description: Delete specific images or bulk-remove all local images (Note: active container dependencies must be stopped and removed first)
Stop Service, Uninstall & Remove Docker
• Stop Service: sudo service docker stop
• Remove Package: sudo yum remove docker
• Description: Safely stop the Docker service daemon and completely remove the Docker package from your Linux system
Docker Container Management Reference Guide
List Running Containers
• Command: docker ps
• Description: Get the list of currently active running containers
Inspect Container Details
• Syntax: docker inspect <container_name>
• Example: docker inspect nginxservice
• Description: Return low-level configuration and state information on Docker objects
Monitor Container Resource Stats
• Syntax: docker stats <container_name>
• Example: docker stats nginxservice
• Description: Display a live stream of container CPU, memory, and network I/O usage statistics
Pause & Unpause Processes
• Pause Syntax: docker pause <container_name> (e.g., docker pause nginxservice)
• Unpause Syntax: docker unpause <container_name> (e.g., docker unpause nginxservice)
• Description: Freeze or resume all running processes within a container
Kill, Start & Stop Containers
• Kill Syntax: docker kill <container_name> (e.g., docker kill nginxservice)
• Start Syntax: docker start <container_name> (e.g., docker start nginxservice)
• Stop Syntax: docker stop <container_name> (e.g., docker stop nginxservice)
• Description: Force-terminate, start, or gracefully stop container execution
List All Containers (All States)
• Command: docker ps -a
• Description: View all containers including stopped, paused, and running instances
Remove & Prune Containers
• Remove Syntax: docker rm <container_name> (e.g., docker rm nginxservice)
• Prune Command: docker container prune
• Description: Delete a specific container or clean up and remove all stopped containers at once
• Note: Container IDs can be used interchangeably with container names across all commands.
Export & Import Container Filesystems
• Run Service: docker run --name newnginxservice -d nginx
• Export Syntax: docker export <container_name> > <file_name>.tar (e.g., docker export newnginxservice > test.tar)
• Import Syntax: docker import <file_name.tar> (e.g., docker import test.tar)
• Description: Export a container's filesystem as a tar archive or import it back as a base image
Diagnose & Manage Docker Service Status
• Check Status: service docker status
• Restart Service: service docker restart
• Description: Troubleshoot download and execution issues by checking if the Docker daemon is active on your host system

Related Articles:

👉 Install Azure PowerShell and Azure AD PowerShell

👉 Install Azure CLI on Windows (Simple & Best Method)

👉 Azure Cloud Shell: Setup Guide and Tutorial