Docker
100 Docker Commands
Set 1:
docker --versionCheck the installed Docker version.docker pull <image-name>Download a Docker image from Docker Hub. Example:docker pull ubuntudocker imagesList all locally available Docker images.docker run <image-name>Run a container from a Docker image. Example:docker run ubuntudocker psShow running containers.docker ps -aShow all containers (running + stopped).docker stop <container-id>Stop a running container.docker rm <container-id>Remove a stopped container.docker rmi <image-id>Remove a Docker image.docker build -t <tag-name> .Build a Docker image from a Dockerfile in the current directory.
2:
docker exec -it <container-id> /bin/bashRun an interactive shell inside a running container.docker logs <container-id>View the logs from a running container.docker-compose upStart services defined in adocker-compose.ymlfile.docker-compose downStop and remove containers, networks, and volumes created bydocker-compose up.docker network lsList all Docker networks.docker volume lsList all Docker volumes.docker inspect <container-id or image-id>Show detailed info (in JSON) about a container or image.docker tag <image-id> <repository:tag>Tag an image for pushing to a registry.docker push <repository:tag>Push an image to a remote repository (e.g., Docker Hub).docker pull <repository:tag>Pull a specific tagged image from a remote registry.
3:
docker loginAuthenticate with a Docker registry (like Docker Hub).docker logoutLog out from a Docker registry.docker save -o <filename>.tar <image-name>Save a Docker image as a tar archive.docker load -i <filename>.tarLoad a Docker image from a tar archive.docker rename <old-container-name> <new-container-name>Rename an existing container.docker statsDisplay real-time resource usage statistics for containers.docker system pruneRemove unused data (stopped containers, unused networks, dangling images).docker container lsSame asdocker ps– list running containers.docker image lsSame asdocker images– list images.docker context lsList all Docker contexts (used for switching between environments like local, cloud, etc.).
4:
docker cp <container-id>:<path-inside-container> <host-path>Copy files/folders from a container to the host.docker cp <host-path> <container-id>:<path-inside-container>Copy files/folders from the host into a container.docker update <container-id> --memory 500mUpdate resource limits of a running container (e.g., memory).docker attach <container-id>Attach to a running container’s STDIN/STDOUT (used for interactive sessions).docker export <container-id> -o <file>.tarExport a container’s filesystem as a tar archive.docker import <file>.tarImport a tarball to create a filesystem image.docker eventsGet a live stream of Docker events (like start, stop, kill).docker history <image-name>Show the history of an image’s layers.docker pause <container-id>Pause all processes in a container.docker unpause <container-id>Resume a paused container.
5:
docker build -f <custom-Dockerfile> -t <tag-name> .Build an image using a custom Dockerfile.docker login <registry-url>Log in to a private Docker registry.docker volume create <volume-name>Create a new Docker volume.docker run -v <volume-name>:<container-path> <image>Mount a volume into a container.docker run -p <host-port>:<container-port> <image>Map container ports to host ports.docker run --name <custom-name> <image>Assign a custom name to a container when you start it.docker run -d <image>Run a container in detached mode (in the background).docker run --rm <image>Automatically remove the container after it exits.docker exec -u <username> <container-id> <command>Run a command in a container as a specific user.docker run --env <key>=<value> <image>Pass environment variables into the container.
6:
docker system dfShow Docker disk usage (images, containers, volumes, build cache).docker run --network <network-name> <image>Run a container on a specific Docker network.docker network create <network-name>Create a custom Docker network.docker run --link <container-name>:<alias> <image>Link one container to another (legacy, use networks instead).docker run --restart=always <image>Automatically restart a container if it stops.docker run --entrypoint <custom-command> <image>Override the default entrypoint of a Docker image.docker inspect -f '{{.NetworkSettings.IPAddress}}' <container>Get a container’s IP address using Go templating.docker image pruneRemove dangling (untagged) images to free space.docker container pruneRemove all stopped containers.docker-compose logs -fFollow logs for all services in adocker-composesetup.
7:
docker compose buildBuild or rebuild services defined in adocker-compose.ymlfile.docker compose restartRestart services managed by Docker Compose.docker compose exec <service> <command>Run a command in a running service container (likedocker execbut via Compose).docker context create <context-name>Create a new Docker context (e.g. to switch between local and cloud environments).docker context use <context-name>Switch to a different Docker context.docker infoDisplay detailed system-wide information about Docker.docker login --username <user> --password-stdinLog in securely by passing the password via stdin.docker run --log-driver=json-file <image>Specify the logging driver for a container.docker run --cap-add=<capability> <image>Add Linux kernel capabilities to a container (for advanced permissions).docker run --device=<host-device>:<container-device>Give the container access to a specific device (e.g., USB, GPU).
8:
docker diff <container-id>Show changes made to a container’s filesystem since it was created.docker run --health-cmd <command>Define a health check command for the container.docker run --tmpfs <container-path>Mount a temporary file storage (tmpfs) inside a container.docker run --read-only <image>Run a container with a read-only root filesystem for extra security.docker create <image>Create a container from an image without starting it.docker start <container-id>Start an existing (created or stopped) container.docker stop $(docker ps -q)Stop all running containers.docker rm $(docker ps -a -q)Remove all containers.docker image ls -f dangling=trueList only dangling (untagged) images.docker container update --restart=no <container-id>Change the restart policy for a container.
9:
docker compose psList containers managed by Docker Compose.docker compose rmRemove stopped Compose services.docker build --no-cache -t <tag> .Build a Docker image without using cache.docker container stats <container-id>Show real-time stats for a specific container.docker logs -f <container-id>Follow the logs output (streaming mode).docker run -it --rm <image> shStart a temporary interactive shell session in a container.docker compose stopStop services defined in a Compose file without removing them.docker-compose configValidate and view the resolveddocker-compose.yml.docker events --filter event=startFilter the Docker event stream to show only container starts.docker exec -it <container-id> envView environment variables inside a running container.
docker buildx create --useCreate and switch to a new BuildKit builder instance for advanced builds (multi-platform, caching).docker buildx build --platform linux/amd64,linux/arm64 -t <image> .Build multi-platform images usingbuildx.docker trust inspect <image>Inspect the signature status of a signed image (Docker Content Trust).docker image inspect <image>Show detailed metadata for a Docker image.docker container top <container>Display running processes inside a container (liketop).docker container rename <old> <new>Rename an existing container.docker image tag <source> <target>Create a new tag for an existing image.docker export <container> | gzip > container.tar.gzExport and compress a container’s filesystem.docker import container.tar.gzImport a container filesystem from a compressed archive.docker compose down --volumes --remove-orphansTear down everything — containers, networks, and volumes, including orphaned services.
Last updated