Skip to main content

One post tagged with "cli"

View All Tags

Docker cli cheat sheet

· 3 min read
Pourya Bagheri
Quantum Computing | Blockchain Soloution | MERN

Docker cli cheat sheet

Displays the installed version of Docker.

docker --version

Shows system-wide information about Docker including the number of containers, images, and more.

docker info

Pulls a Docker image from Docker Hub or another registry.

docker pull <image_name>

Builds an image from a Dockerfile located in the specified directory.

docker build -t <tag_name> <path>

Lists all available Docker images on your local machine.

docker images

Lists all running containers.

docker ps

Lists all containers, including stopped ones.

docker ps -a

Runs a container from the specified image.

docker run <image_name>

Runs a container in detached mode.

docker run -d <image_name>

Maps a port on the host machine to a port in the container.

docker run -p <host_port>:<container_port> <image_name>

Executes a command inside a running container.

docker exec -it <container_id> <command>

Stops a running container.

docker stop <container_id>

Starts a stopped container.

docker start <container_id>

Restarts a running or stopped container.

docker restart <container_id>

Removes a stopped container.

docker rm <container_id>

Removes a Docker image.

docker rmi <image_id>

Fetches logs of a running or stopped container.

docker logs <container_id>

Lists all Docker networks.

docker network ls

Lists all Docker volumes.

docker volume ls

Starts up all containers defined in the docker-compose.yml file.

docker-compose up

Stops and removes all containers defined in the docker-compose.yml file.

docker-compose down

Builds images for the services defined in the docker-compose.yml file.

docker-compose build

Fetches logs for all containers defined in the docker-compose.yml file.

docker-compose logs

Lists files inside a running container.

docker exec <container_id> ls

Lists all Docker images, including intermediate layers.

docker images -a

Builds an image without using cache, ensuring all steps are re-executed.

docker build --no-cache -t <tag_name> .

Retrieves detailed information about a container or image.

docker inspect <container_id>

Opens an interactive bash shell inside a running container.

docker exec -it <container_id> bash

Customizes the output of the docker info command.

docker info --format '{{.Containers}}'

Attaches to a running container's standard input, output, and error streams.

docker attach <container_id>

Displays live statistics of running containers.

docker stats

Pulls all tags of a Docker image.

docker pull --all-tags <image_name>

Tags an image with a new name.

docker tag <image_id> <new_image_name>

Copies files or directories from a container to the host.

docker cp <container_id>:<container_path> <host_path>

Copies files or directories from the host to a container.

docker cp <host_path> <container_id>:<container_path>

Automatically removes the container when it stops.

docker run --rm <image_name>

Logs in to a Docker registry.

docker login <registry_url>

Logs out from a Docker registry.

docker logout

Removes unused Docker objects like containers, networks, and volumes.

docker prune

Retrieves detailed information about a Docker network.

docker network inspect <network_name>