Docker

100 Docker Commands

Set 1:

  1. docker --version Check the installed Docker version.

  2. docker pull <image-name> Download a Docker image from Docker Hub. Example: docker pull ubuntu

  3. docker images List all locally available Docker images.

  4. docker run <image-name> Run a container from a Docker image. Example: docker run ubuntu

  5. docker ps Show running containers.

  6. docker ps -a Show all containers (running + stopped).

  7. docker stop <container-id> Stop a running container.

  8. docker rm <container-id> Remove a stopped container.

  9. docker rmi <image-id> Remove a Docker image.

  10. docker build -t <tag-name> . Build a Docker image from a Dockerfile in the current directory.


2:

  1. docker exec -it <container-id> /bin/bash Run an interactive shell inside a running container.

  2. docker logs <container-id> View the logs from a running container.

  3. docker-compose up Start services defined in a docker-compose.yml file.

  4. docker-compose down Stop and remove containers, networks, and volumes created by docker-compose up.

  5. docker network ls List all Docker networks.

  6. docker volume ls List all Docker volumes.

  7. docker inspect <container-id or image-id> Show detailed info (in JSON) about a container or image.

  8. docker tag <image-id> <repository:tag> Tag an image for pushing to a registry.

  9. docker push <repository:tag> Push an image to a remote repository (e.g., Docker Hub).

  10. docker pull <repository:tag> Pull a specific tagged image from a remote registry.


3:

  1. docker login Authenticate with a Docker registry (like Docker Hub).

  2. docker logout Log out from a Docker registry.

  3. docker save -o <filename>.tar <image-name> Save a Docker image as a tar archive.

  4. docker load -i <filename>.tar Load a Docker image from a tar archive.

  5. docker rename <old-container-name> <new-container-name> Rename an existing container.

  6. docker stats Display real-time resource usage statistics for containers.

  7. docker system prune Remove unused data (stopped containers, unused networks, dangling images).

  8. docker container ls Same as docker ps – list running containers.

  9. docker image ls Same as docker images – list images.

  10. docker context ls List all Docker contexts (used for switching between environments like local, cloud, etc.).


4:

  1. docker cp <container-id>:<path-inside-container> <host-path> Copy files/folders from a container to the host.

  2. docker cp <host-path> <container-id>:<path-inside-container> Copy files/folders from the host into a container.

  3. docker update <container-id> --memory 500m Update resource limits of a running container (e.g., memory).

  4. docker attach <container-id> Attach to a running container’s STDIN/STDOUT (used for interactive sessions).

  5. docker export <container-id> -o <file>.tar Export a container’s filesystem as a tar archive.

  6. docker import <file>.tar Import a tarball to create a filesystem image.

  7. docker events Get a live stream of Docker events (like start, stop, kill).

  8. docker history <image-name> Show the history of an image’s layers.

  9. docker pause <container-id> Pause all processes in a container.

  10. docker unpause <container-id> Resume a paused container.


5:

  1. docker build -f <custom-Dockerfile> -t <tag-name> . Build an image using a custom Dockerfile.

  2. docker login <registry-url> Log in to a private Docker registry.

  3. docker volume create <volume-name> Create a new Docker volume.

  4. docker run -v <volume-name>:<container-path> <image> Mount a volume into a container.

  5. docker run -p <host-port>:<container-port> <image> Map container ports to host ports.

  6. docker run --name <custom-name> <image> Assign a custom name to a container when you start it.

  7. docker run -d <image> Run a container in detached mode (in the background).

  8. docker run --rm <image> Automatically remove the container after it exits.

  9. docker exec -u <username> <container-id> <command> Run a command in a container as a specific user.

  10. docker run --env <key>=<value> <image> Pass environment variables into the container.


6:

  1. docker system df Show Docker disk usage (images, containers, volumes, build cache).

  2. docker run --network <network-name> <image> Run a container on a specific Docker network.

  3. docker network create <network-name> Create a custom Docker network.

  4. docker run --link <container-name>:<alias> <image> Link one container to another (legacy, use networks instead).

  5. docker run --restart=always <image> Automatically restart a container if it stops.

  6. docker run --entrypoint <custom-command> <image> Override the default entrypoint of a Docker image.

  7. docker inspect -f '{{.NetworkSettings.IPAddress}}' <container> Get a container’s IP address using Go templating.

  8. docker image prune Remove dangling (untagged) images to free space.

  9. docker container prune Remove all stopped containers.

  10. docker-compose logs -f Follow logs for all services in a docker-compose setup.


7:

  1. docker compose build Build or rebuild services defined in a docker-compose.yml file.

  2. docker compose restart Restart services managed by Docker Compose.

  3. docker compose exec <service> <command> Run a command in a running service container (like docker exec but via Compose).

  4. docker context create <context-name> Create a new Docker context (e.g. to switch between local and cloud environments).

  5. docker context use <context-name> Switch to a different Docker context.

  6. docker info Display detailed system-wide information about Docker.

  7. docker login --username <user> --password-stdin Log in securely by passing the password via stdin.

  8. docker run --log-driver=json-file <image> Specify the logging driver for a container.

  9. docker run --cap-add=<capability> <image> Add Linux kernel capabilities to a container (for advanced permissions).

  10. docker run --device=<host-device>:<container-device> Give the container access to a specific device (e.g., USB, GPU).


8:

  1. docker diff <container-id> Show changes made to a container’s filesystem since it was created.

  2. docker run --health-cmd <command> Define a health check command for the container.

  3. docker run --tmpfs <container-path> Mount a temporary file storage (tmpfs) inside a container.

  4. docker run --read-only <image> Run a container with a read-only root filesystem for extra security.

  5. docker create <image> Create a container from an image without starting it.

  6. docker start <container-id> Start an existing (created or stopped) container.

  7. docker stop $(docker ps -q) Stop all running containers.

  8. docker rm $(docker ps -a -q) Remove all containers.

  9. docker image ls -f dangling=true List only dangling (untagged) images.

  10. docker container update --restart=no <container-id> Change the restart policy for a container.


9:

  1. docker compose ps List containers managed by Docker Compose.

  2. docker compose rm Remove stopped Compose services.

  3. docker build --no-cache -t <tag> . Build a Docker image without using cache.

  4. docker container stats <container-id> Show real-time stats for a specific container.

  5. docker logs -f <container-id> Follow the logs output (streaming mode).

  6. docker run -it --rm <image> sh Start a temporary interactive shell session in a container.

  7. docker compose stop Stop services defined in a Compose file without removing them.

  8. docker-compose config Validate and view the resolved docker-compose.yml.

  9. docker events --filter event=start Filter the Docker event stream to show only container starts.

  10. docker exec -it <container-id> env View environment variables inside a running container.


  1. docker buildx create --use Create and switch to a new BuildKit builder instance for advanced builds (multi-platform, caching).

  2. docker buildx build --platform linux/amd64,linux/arm64 -t <image> . Build multi-platform images using buildx.

  3. docker trust inspect <image> Inspect the signature status of a signed image (Docker Content Trust).

  4. docker image inspect <image> Show detailed metadata for a Docker image.

  5. docker container top <container> Display running processes inside a container (like top).

  6. docker container rename <old> <new> Rename an existing container.

  7. docker image tag <source> <target> Create a new tag for an existing image.

  8. docker export <container> | gzip > container.tar.gz Export and compress a container’s filesystem.

  9. docker import container.tar.gz Import a container filesystem from a compressed archive.

  10. docker compose down --volumes --remove-orphans Tear down everything — containers, networks, and volumes, including orphaned services.


Last updated