Docker Cheat Sheet

Docker Cheat Sheet

Day 20 of 90daysofdevops

ยท

4 min read

Docker Images


  1. List all available Docker images on your system

     docker images
    
  2. Download a Docker image from a registry

     docker pull <image_name>
    
  3. Push an image to a registry

     docker push <image_name>
    
  4. Remove a Docker image from your system

     docker rmi <image_name>
    
  5. Build a Docker image from a Dockerfile

     docker build -t <image_name> <path_to_Dockerfile>
    
  6. Build an image from a Dockerfile located in the current directory

     docker build .
    
  7. Create an image from a Dockerfile and tag it

     docker build -t [name]:[tag] [dockerfile-path]
    
  8. Create an image from a container

     docker commit [container] [new-image]
    
  9. Tag an image

     docker tag [image] [image]:[tag]
    
  10. Show history for an image

    docker history [image]
    
  11. Save an image to a tar archive file

    docker save [image] > [tar-file]
    
  12. Remove unused images

    docker image prune
    

Docker Containers


  1. Create and start a new container from a Docker image

     docker run <image_name>
    
  2. List all running containers

     docker ps
    
  3. Stop a running container

     docker stop <container_id>
    
  4. Start a stopped container

     docker start <container_id>
    
  5. Restart a running container

     docker restart <container_id>
    
  6. Pause process in a running container

     docker pause <container_id>
    
  7. Unpause the process in a running container

     docker unpause <container_id>
    
  8. Remove a stopped container from your system

     docker rm <container_id>
    
  9. Send a KILL signal to stop a container

     docker kill <container_id>
    
  10. Execute a command inside a running container

    docker exec -it <container_id> <command>
    
  11. View the logs of a container

    docker logs <container_id>
    
  12. Run a container and remove it after it stops

    docker run -rm <image>
    
  13. Run an interactive process

    docker run -it <image>
    

Docker Container Management


  1. Create a container (without starting it)

     docker create [image]
    
  2. Create an interactive container with pseudo-TTY

     docker create -it [image]
    
  3. Rename an existing container

     docker rename [container] [new-name]
    
  4. Forcefully remove a container, even if it is running

     docker rm -f [container]
    
  5. Retrieve logs created before a specific point in time

     docker logs -f --until=[interval] [container]
    
  6. Update the configuration of one or more containers

     docker update [container]
    
  7. View port mapping for a container

     docker port [container]
    
  8. Show running processes in a container

     docker top [container]
    
  9. View live resource usage statistics for a container

     docker stats [container]
    
  10. Show changes to files or directories on the filesystem

    docker diff [container]
    
  11. Copy a local file to a directory in a container

    docker cp [file-path] CONTAINER:[path]
    

Docker Compose


  1. Start containers defined in a Docker Compose file

     docker-compose up
    
  2. Stop and remove containers defined in a Docker Compose file

     docker-compose down
    
  3. Build or rebuild services defined in a Docker Compose file

     docker-compose build
    
  4. View the logs of a specific service defined in a Docker Compose file

     docker-compose logs <service_name>
    

Docker Networks


  1. List all available Docker networks

     docker network ls
    
  2. Create a new Docker network

     docker network create <network_name>
    
  3. Inspect details about a Docker network

     docker network inspect <network_name>
    
  4. Remove a Docker network

     docker network rm <network_name>
    

Docker Volumes


  1. List all available Docker volumes

     docker volume ls
    
  2. Create a new Docker volume

     docker volume create <volume_name>
    
  3. Inspect details about a Docker volume

     docker volume inspect <volume_name>
    
  4. Remove a Docker volume

     docker volume rm <volume_name>
    

General Management


  1. Log in to a Docker registry

     docker login
    
  2. Log out of a Docker registry

     docker logout
    
  3. List low-level information on Docker objects

     docker inspect [object]
    
  4. Show the version of the local Docker installation

     docker version
    
  5. Display information about the system

     docker info
    
  6. Remove unused images, containers, and networks

     docker system prune
    

Thank You,

I want to express my deepest gratitude to each and every one of you who has taken the time to read, engage, and support my journey as a becoming DevOps Engineer.

Feel free to reach out to me if any corrections or add-ons are required on blogs. Your feedback is always welcome & appreciated.

~ Abhisek Moharana ๐Ÿ˜Š

ย