Docker Command Cheat sheet

Suraj barikSuraj barik
2 min read

Quick reference guide for Docker commands along with examples to help you get started.

Installation

Sudo apt-get update
sudo apt-get install docker.io

To grant access to your user to run the docker command

sudo usermod -aG docker $USER
sudo reboot

Managing Images

# docker images: Lists all the images on the local system.

docker images

# docker build: Builds an image from a Dockerfile.

docker build -t <image_name> .

# docker pull: Pulls an image or a repository from a registry.

docker pull <image-name:tag>

# docker push: Pushes an image or a repository to a registry.

docker push <image-name:tag>

# docker rmi: Removes one or more images.

docker rmi <image-name>

Managing Containers

# docker run : Runs a command in a new container.

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
docker run -d --name <container-name> -p 8000:8000 <Image Name>

# docker exec: Runs a command in a running container and goes inside a container.

docker exec -it <container-name or ID> bash

Starting & Stopping Containers

docker start <container-name>
docker stop <container-name>

# docker kill: Kill the containers.

docker kill <container-name or ID>

# docker rm: Removes one or more containers.

docker rm <container-name or ID>

# docker ps: Lists all running containers.

docker ps 
#Show all the containers
docker ps -a

# docker logs: Fetches the logs of a container.

docker logs <container ID>

# docker inspect: Returns low-level information on a container or image.

docker inspect <container-name or ID>

Docker Volume:

# docker volume create: Create a volume

docker volume create <volume-name>

# docker volume ls: List all volumes

docker volume ls

# docker volume inspect: Display detailed information on one or more volumes

docker volume inspect <volume-name>

# docker volume rm : Remove one or more volumes

docker volume rm <volume-name>

# docker volume prune: Remove all unused volumes

docker volume prune

Docker Compose:

# docker-compose up: Create and start containers

docker-compose up

# docker-compose down: Stop and remove containers, networks, images, and volumes

docker-compose down

# docker-compose ps: List containers

docker-compose ps

# docker-compose logs: Show logs

docker-compose logs <service>

Networking:

# docker-network create: create a newdocker network

docker network create <name of network>

# docker-network ls: list out the Docker networks

docker network ls

# docker-network inspect: all the information you need about that network

docker network inspect <network-name>

0
Subscribe to my newsletter

Read articles from Suraj barik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suraj barik
Suraj barik

I'm Suraj Barik Aspiring DevOps Engineer with Hands-on experience in Automating,Shell Scripting, Supporting in AWS, management, CI/CD, and DevOps processes.