Day 20 Task - Docker Cheatsheet

Day 20 Task - Docker Cheatsheet

ยท

3 min read

Introduction:

Welcome to the Docker Cheat Sheet! Whether you're working with containers, managing images, or setting up services, this guide is here to help you in the vast world of Docker. Let's simplify and boost your DevOps skills together on this Docker adventure!

Docker Basics:

  1. Run a Container:

     docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
    
  2. List Running Containers:

     docker ps
    
  3. List All Containers:

     docker ps -a
    
  4. Stop a Running Container:

     docker stop CONTAINER_ID
    
  5. Remove a Container:

     docker rm CONTAINER_ID
    
  6. Remove All Stopped Containers:

     docker container prune
    
  7. Inspect Container Details:

     docker inspect CONTAINER_ID
    
  8. Attach to a Running Container:

     docker exec -it CONTAINER_ID /bin/bash
    

Image Manipulation:

  1. List Local Images:

     docker images
    
  2. Pull an Image from Docker Hub:

     docker pull IMAGE[:TAG]
    
  3. Build an Image from Dockerfile:

     docker build -t IMAGE_NAME:TAG PATH_TO_DOCKERFILE
    
  4. Remove an Image:

     docker rmi IMAGE_ID
    
  5. Remove All Unused Images:

     docker image prune
    

Networking:

  1. List Networks:

     docker network ls
    
  2. Inspect Network Details:

     docker network inspect NETWORK_ID
    
  3. Create a Bridge Network:

     docker network create --driver bridge NETWORK_NAME
    
  4. Connect Container to Network:

     docker network connect NETWORK_NAME CONTAINER_NAME
    
  5. Disconnect Container from Network:

     docker network disconnect NETWORK_NAME CONTAINER_NAME
    

Volume Management:

  1. List Volumes:

     docker volume ls
    
  2. Inspect Volume Details:

     docker volume inspect VOLUME_NAME
    
  3. Create a Volume:

     docker volume create VOLUME_NAME
    
  4. Remove a Volume:

     docker volume rm VOLUME_NAME
    

Container Logs:

  1. View Container Logs:

     docker logs CONTAINER_ID
    
  2. Tail Container Logs:

     docker logs -f CONTAINER_ID
    

Docker-Compose:

  1. Run Docker Compose:

     docker-compose up -d
    
  2. Stop Docker Compose Services:

     docker-compose down
    
  3. Build and Run Docker Compose:

     docker-compose up --build -d
    

Docker System:

  1. Display System-Wide Information:

     docker info
    
  2. Show Docker Disk Usage:

     docker system df
    
  3. Remove All Unused Data:

     docker system prune
    

Docker Registry:

  1. Login to Docker Hub:

     docker login
    
  2. Push Image to Docker Hub:

     docker push IMAGE[:TAG]
    
  3. Pull Image from Private Registry:

     docker pull REGISTRY_URL/IMAGE[:TAG]
    

Docker Security:

  1. Check Container Vulnerabilities:

     docker scan IMAGE[:TAG]
    
  2. Run Container with Security Options:

     docker run --security-opt seccomp=unconfined --cap-add=SYS_PTRACE -it IMAGE[:TAG]
    
  3. Run Container with Read-only Filesystem:

     docker run --read-only -it IMAGE[:TAG]
    

Docker Stats:

  1. Display Real-time Container Resource Usage:

     docker stats CONTAINER_ID
    

Docker Events:

  1. Monitor Docker Events:

     docker events
    

Docker Debugging:

  1. Inspect Docker Bridge Network:

     docker network inspect bridge
    
  2. View Docker Daemon Logs:

     journalctl -u docker
    
  3. Check Docker Version:

     docker version
    

49. Copy Files between Host and Container:

docker cp SOURCE_PATH CONTAINER_ID:DEST_PATH
  1. Create a Custom Docker Bridge Network:
docker network create --driver bridge --subnet=SUBNET_NAME CUSTOM_NETWORK_NAME

Conclusion:

And there you have it โ€“ the Docker Cheat Sheet is now at your fingertips! Whether you're delving into containers, managing services, or exploring volumes and networks, just remember: Docker is your ally in making DevOps simpler. Here's to smoother operations and a journey of continuous learning! Happy Dockerizing! ๐Ÿš€๐Ÿณ

#Docker #DevOps #CheatSheet #HappyLearning

Did you find this article valuable?

Support Akash Dhengale by becoming a sponsor. Any amount is appreciated!

ย