Sitemap
DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.

Docker Cheat sheet

2 min readFeb 12, 2024

--

Press enter or click to view image in full size

Docker Basics :


// Check Docker version.
docker --version or docker -V

// Display system-wide information about Docker.
docker info

// Download an image from Docker Hub.
docker pull <image_name>

// List local Docker images.
docker images or docker image ls

// List running containers.
docker ps or docker container ls

// List all containers (including stopped ones
docker ps -a or docker container ls -a

// Create and start a new container from an image.
docker run <options> <image_name>

Container Lifecycle :

// Start a stopped container.
docker start <container_name/id>

// Stop a running container gracefully.
docker stop <container_name/id>

// Forcefully stop a running container.
docker kill <container_name/id>

// Restart a container
docker restart <container_name/id>

// Remove a stopped container.
docker rm <container_name/id>

Images :

// Build a docker image from a Dockerfile
docker build -t <image_name> <path_to_dockerfile>

//Remove an image
docker rmi <image_name>

//Remove all unused images
docker image prune

Docker Compose :

// Start services defined in a Docker Compose file
docker-compose up

// Stop and remove services defined in a Docker Compose file.
docker-compose down

// List services in a Compose file and their status.
docker-compose ps

// View logs for a specific service.
docker-compose logs <service_name>

// Run a command in a running service container.
docker-compose exec <service_name> <command>

Get Jay Kava’s stories in your inbox

Join Medium for free to get updates from this writer.

Volumes :

// Create a named volume:
docker volume create <volume_name>

// Mount a volume to a container..
docker run -v <volume_name>:<container_path>

// List volumes
docker volume ls

// Remove a volume
docker volume rm <volume_name>

Docker Registry and Hub :

// Log in to a Docker registry
docker login

// Push an image to a registry
docker push <image_name>

// Pull an image from a registry
docker pull <image_name>

Networks :

// Create a user-defined network:
docker network create <network_name>

// List networks
docker network ls

// Connect a container to a network
docker network connect <network_name> <container_name/id>

//Disconnect a container from a network
docker network disconnect <network_name> <container_name/id>

Logs and Debugging :

// View container logs
docker logs <container_name/id>

// Start an interactive shell in a running container
docker exec-it <container_name/id> /bin/bash

// Display real-time container resource usage
docker stats <container_name/id>

CleanUp :

// Remove all stopped containers, unused networks, and images
docker system prune

//all info about docker image and size
docker system df

// Remove all stopped containers
docker container prune

// Remove all unused images
docker image prune

// Remove all unused volumes
docker volume prune

If you found this article helpful, please don’t forget to hit the Follow and Clap buttons to help me write more articles like this.
Thank You 🖤

You can contact me on: LinkedIn

--

--

Jay Kava
Jay Kava

DevOps & Cloud Engineer | AWS | Azure | Kubernetes | Docker | CI/CD | Terraform | Helm | Follow for deep drive in world of Cloud

DevOps.dev
DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.