Useful Docker Commands In daily use

Useful Docker Commands In daily use


4 min read

Docker Basics

  1. docker version

    • Shows the Docker version installed on your system.

    •   docker version
  2. docker info

    • Displays system-wide information about Docker, including number of containers, images, and other details.

        docker info
  3. docker help

    • Provides help on using Docker commands.

        docker help

Working with Images

  1. docker pull

    • Downloads an image from a Docker registry (e.g., Docker Hub).

        docker pull <image_name>
  2. docker images

    • Lists all the images on your local machine.

        docker images
  3. docker rmi

    • Removes one or more images from your local machine.

    •   docker rmi <image_id>
  4. docker tag

    • Tags an image with a new name.

        docker tag <existing_image> <new_image:tag>
  5. docker build

    • Builds an image from a Dockerfile.

        docker build -t <image_name:tag> <path_to_dockerfile>
  6. docker push

    • Uploads an image to a Docker registry.

        docker push <image_name:tag>

Working with Containers

  1. docker run

    • Runs a container from an image.

        docker run -d --name <container_name> <image_name>
  2. docker ps

    • Lists all running containers.

        docker ps
  3. docker ps -a

    • Lists all containers, including stopped ones.

        docker ps -a
  4. docker stop

    • Stops a running container.

        docker stop <container_id>
  5. docker start

    • Starts a stopped container.

        docker start <container_id>
  6. docker restart

    • Restarts a container.

        docker restart <container_id>
  7. docker rm

    • Removes a container.

        docker rm <container_id>
  8. docker logs

    • Displays the logs of a container.

        docker logs <container_id>
  9. docker exec

    • Runs a command in a running container.

        docker exec -it <container_id> <command>
  10. docker attach

    • Attaches your terminal to a running container.

        docker attach <container_id>

Container Networking

  1. docker network ls

    • Lists all Docker networks.

        docker network ls
  2. docker network create

    • Creates a new Docker network.

        docker network create <network_name>
  3. docker network inspect

    • Displays detailed information about a network.

        docker network inspect <network_name>
  4. docker network connect

    • Connects a container to a network.

        docker network connect <network_name> <container_id>
  5. docker network disconnect

    • Disconnects a container from a network.

        docker network disconnect <network_name> <container_id>

Docker Volumes

  1. docker volume ls

    • Lists all Docker volumes.

        docker volume ls
  2. docker volume create

    • Creates a new Docker volume.

        docker volume create <volume_name>
  3. docker volume inspect

    • Displays detailed information about a volume.

        docker volume inspect <volume_name>
  4. docker volume rm

    • Removes a Docker volume.

        docker volume rm <volume_name>

Docker Compose

  1. docker-compose up

    • Builds, (re)creates, starts, and attaches to containers for a service defined in a docker-compose.yml file.

        docker-compose up
  2. docker-compose down

    • Stops and removes containers, networks, volumes, and images created by docker-compose up.

        docker-compose down
  3. docker-compose ps

    • Lists containers started by Docker Compose.

        docker-compose ps
  4. docker-compose logs

    • Displays log output from services managed by Docker Compose.

        docker-compose logs
  5. docker-compose exec

    • Executes a command in a running service container.

        docker-compose exec <service_name> <command>

Cleanup Commands

  1. docker system prune

    • Removes all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.

        docker system prune
  2. docker container prune

    • Removes all stopped containers.

        docker container prune
  3. docker image prune

    • Removes unused images.

        docker image prune
  4. docker volume prune

    • Removes all unused volumes.

        docker volume prune

Inspecting and Debugging

  1. docker inspect

    • Returns low-level information about Docker objects.

        docker inspect <container_id or image_id>
  2. docker diff

    • Inspects changes to files or directories on a container’s filesystem.

        docker diff <container_id>


  1. docker scan

    • Scans your Docker images for vulnerabilities.

        docker scan <image_name>

By mastering these commands, you can effectively manage Docker images, containers, networks, volumes, and more, enhancing your ability to deploy and maintain containerized applications.

Did you find this article valuable?

Support Deven by becoming a sponsor. Any amount is appreciated!