Docker Overview

  1. What Is Docker?



  2. Why Use Docker?



  3. Understanding Images vs Containers



  4. What Is a Dockerfile?



  5. Basic Docker Commands



  6. Layered Architecture of Docker



  7. Bind Mounts vs Volumes



  8. Docker Compose Overview



  9. Docker Hub



  10. Docker in Production



  11. Best Practices



Docker Hub

  1. What Is Docker Hub?



  2. Using Docker Hub Without Logging In



  3. Creating a Docker Hub Account



  4. Pushing an Image to Docker Hub



  5. Pulling Images from Docker Hub



  6. Repositories and Tags




Docker Images

  1. How Docker Images Work?



  2. Base Images vs Child Images



  3. Viewing Docker Images



  4. Building Docker Images



  5. Tagging Docker Images



  6. Pulling Docker Images



  7. Running Containers from Images



  8. Layered Filesystem Explained



  9. Best Practices for Docker Images



  10. Multi-Stage Builds (Advanced)



  11. Summary


Docker Containers

  1. What Are Docker Containers?



  2. Creating and Running Containers



  3. Viewing and Managing Containers



  4. Container File System



  5. Executing Commands Inside Containers



  6. Container Networking



  7. Container Volumes



  8. Container Lifecycle



  9. Container Logs



  10. Cleaning Up Containers




Dockerfile Anatomy

  1. What Is a Dockerfile?



  2. The Structure of a Dockerfile



  3. FROM — Choosing a Base Image



  4. WORKDIR — Setting Working Directory



  5. COPY and ADD — Adding Files



  6. RUN — Execute Commands During Build



  7. ENV — Environment Variables



  8. ARG — Build-Time Variables



  9. EXPOSE — Documenting Port Usage



  10. CMD — The Default Container Command



  11. ENTRYPOINT — Forced Command



  12. VOLUME — Persistent Data Storage



  13. USER — Change the Running User



  14. LABEL — Metadata



  15. HEALTHCHECK — Container Health Verification



  16. Full Dockerfile Example



Introduction to Docker Commands

  1. What Are Docker Commands?



  2. Types of Docker Commands (High-Level Overview)

    1. Container Management

    2. Command Description
      docker runCreate and start a new container.
      docker startStart an existing stopped container.
      docker stopStop a running container.
      docker restartRestart a container.
      docker execRun a command inside a running container.
      docker logsView container logs.

    3. Image Management

    4. Command Description
      docker buildBuild a Docker image from a Dockerfile.
      docker pullDownload an image from a registry.
      docker pushUpload an image to a registry.
      docker imagesList local Docker images.
      docker rmiRemove one or more images.

    5. Volume Management

    6. Command Description
      docker volume createCreate a volume.
      docker volume lsList volumes.
      docker volume inspectInspect volume configuration.

    7. Network Management

    8. Command Description
      docker network createCreate a network.
      docker network lsList networks.
      docker network inspectDisplay detailed network information.

    9. System Cleanup

    10. Command Description
      docker system pruneRemove unused containers, networks, images, and cache.
      docker container pruneRemove all stopped containers.
      docker volume pruneRemove all unused volumes.


  3. System Commands



  4. Docker Help Commands




Understanding the docker run Command

  1. What Is It?



  2. Running a Simple Container



  3. -it — Interactive Mode



  4. -d — Run in Detached Mode (Background)



  5. -p — Publishing Ports



  6. -v — Mounting Volumes



  7. --name — Naming a Container



  8. -e — Setting Environment Variables



  9. --rm — Auto-remove After Exit



  10. -w — Working Directory



  11. --network — Attach Container to a Network



  12. --entrypoint — Override the Default Entry Command



  13. --cpu and --memory — Resource Limiting



  14. Combining Multiple Options




Understanding the docker start Command

  1. What Is docker start?



  2. Starting an Existing Container



  3. List Containers Before Starting Them



  4. -a — Attach to the Container Output



  5. -i — Attach Standard Input (STDIN)



  6. Starting Multiple Containers at Once



  7. Check Status After Starting



  8. Difference Between docker start and docker restart



  9. Example Workflow: Create with run, Start Again with start




Understanding the docker stop Command

  1. What Is docker stop?



  2. Stopping a Running Container



  3. Stopping Multiple Containers



  4. Understanding Signal Workflow



  5. -t — Changing the Timeout Before Force-Kill



  6. What Happens to Processes Inside the Container?



  7. Stopping All Running Containers



  8. Difference Between docker stop and docker kill



  9. Example Workflow: Stop → Start → Attach




Understanding the docker restart Command

  1. What Is docker restart?



  2. Restarting a Container



  3. Using Timeout with -t



  4. Restarting Multiple Containers



  5. Example Workflow: Updating Configuration and Restarting



  6. Example: Fast Restart with Custom Timeout




Understanding the docker exec Command

  1. What Is docker exec?



  2. Running a Simple Command Inside a Container



  3. -it — Interactive Shell Inside the Container



  4. -d — Execute in Detached Mode



  5. Executing Commands as Another User (-u)



  6. Passing Environment Variables Using env



  7. Executing Long-Running Processes



  8. Checking Process Status Inside Container



  9. Example: Inspect an Nginx Web Server Container



  10. Example: Debugging a Python App



  11. Important Limitations of docker exec




Understanding the docker logs Command

  1. What Is docker logs?



  2. Viewing Logs of a Container



  3. -f — Follow Logs in Real Time



  4. --tail — View Only the Last X Lines



  5. -t — Show Timestamps



  6. Combine Options: Follow + Tail + Timestamp



  7. Viewing Logs from Stopped Containers



  8. Example: Debugging a Crash



  9. Log Output from a Web Server (Example)



  10. Filtering Output with grep (Shell Feature)



  11. Difference Between docker logs and docker exec for Log Files



  12. Where Are Docker Logs Stored on Host?




Understanding the docker build Command

  1. What Is docker build?



  2. Building an Image from a Dockerfile



  3. -t — Tagging an Image



  4. -f — Build with a Custom Dockerfile Name



  5. Understanding the Build Context



  6. --no-cache — Build Without Using Cache



  7. --pull — Always Pull the Newest Base Image



  8. --build-arg — Pass Build Arguments



  9. Building from a Git Repository



  10. Building from Standard Input (-)



  11. Checking Built Images



  12. Example Workflow: Build → Run → Test



  13. Common Mistakes and Tips




Understanding the docker pull Command

  1. What Is docker pull?



  2. Pulling an Image from Docker Hub



  3. Pulling a Specific Tagged Version



  4. Pulling by Digest (@sha256:...)



  5. --platform — Pull Image for Specific Architecture



  6. Pulling Images from Private Registries



  7. Pulling All Tags of an Image (Not Native to Docker)



  8. When Should You Run docker pull?


  9. Example Workflow: Pull → Run → Inspect




Understanding the docker push Command

  1. What Is docker push?



  2. Tagging an Image Before Pushing



  3. Pushing an Image to Docker Hub



  4. Logging In Before Pushing



  5. Pushing to a Private Registry



  6. Pushing Multiple Tags



  7. Pushing by Digest



  8. Checking Local Images Before Pushing



  9. Example Workflow: Build → Tag → Push




Understanding the docker volume Command

  1. What Is docker volume?



  2. Listing Volumes with docker volume ls



  3. Creating a New Volume



  4. Inspecting a Volume



  5. Using a Volume with docker run



  6. Creating and Mounting Volume Automatically



  7. Viewing Mounted Volumes Inside a Container



  8. Removing a Volume (docker volume rm)



  9. Removing All Unused Volumes — docker volume prune



  10. Difference Between Volumes, Bind Mounts, and tmpfs



  11. Example: Persisting PostgreSQL Data
  12. docker volume create pgdata
    
    docker run -d                        \
      --name pg                          \
      -e POSTGRES_PASSWORD=12345         \
      -v pgdata:/var/lib/postgresql/data \
      postgres:15
    


  13. Example: Sharing a Volume Between Multiple Containers
  14. docker run -d --name c1 -v sharedvol:/data alpine
    docker run -d --name c2 -v sharedvol:/data alpine
    


  15. Where Docker Volumes Are Stored on Host




Understanding the docker network Command

  1. What Is docker network?



  2. Listing Existing Docker Networks


  3. Creating a Custom Network



  4. Creating a Network with Custom Subnet and Gateway


  5. Inspecting a Network
  6. docker network inspect mynet
    {
        "Name": "mynet",
        "Driver": "bridge",
        "Containers": {
            "abcd1234": {
                "Name": "web",
                "IPv4Address": "172.18.0.2/16"
            }
        }
    }
    


  7. Running a Container Attached to a Network
  8. docker run -d --name webapp --network mynet nginx
    


  9. Connecting an Existing Container to a Network
  10. docker network connect mynet backend


  11. Disconnecting a Container from a Network
  12. docker network disconnect mynet backend


  13. Removing a Docker Network
  14. docker network rm mynet


  15. Removing All Unused Networks — docker network prune
  16. docker network prune


  17. Understanding Docker Network Drivers



  18. Example: Two Containers Talking to Each Other



  19. Example: Static IP Assignment
  20. 
    docker network create --subnet=172.20.0.0/16 appnet
    
    docker run -d --name app1 --network appnet --ip 172.20.0.10 alpine
    docker run -d --name app2 --network appnet --ip 172.20.0.11 alpine
    



Understanding the Docker Daemon (dockerd)

  1. What Is the Docker Daemon?



  2. Architecture: How Docker CLI Talks to the Daemon



  3. Why the Docker Daemon Requires Root Privileges



  4. The Famous Security Problem: Access to /var/run/docker.sock



  5. Rootless Docker: Attempt to Solve the Problem



  6. Why Kubernetes Stopped Using Docker as Runtime



  7. Alternatives to Docker That Avoid the Daemon




Understanding the docker compose Command

  1. What Is docker compose?



  2. Understanding the docker-compose.yml Structure



  3. Starting a Compose Application — docker compose up



  4. Stopping a Compose Application — docker compose down


  5. Viewing Logs — docker compose logs


  6. Listing All Services — docker compose ps


  7. Building Images — docker compose build



  8. Running Commands in Services — docker compose exec



  9. Viewing Container Resource Usage — docker compose top
  10. docker compose top


  11. Stopping and Starting Individual Services



  12. Scaling Services — --scale
  13. docker compose up -d --scale web=3


  14. Using Environment Files



  15. Example: Web + Database Compose Setup




How to Write a docker-compose.yml File

  1. What Is docker-compose.yml?



  2. Basic Structure of a Compose File



  3. Step 1: Start with services



  4. Step 2: Choose image or build for Each Service



  5. Step 3: Expose Ports with ports



  6. Step 4: Add Environment Variables with environment



  7. Step 5: Persist Data with volumes



  8. Step 6: Define Networks (Optional but Helpful)



  9. Step 7: Control Start Order with depends_on



  10. Step 8: Override Commands with command and restart Policy



  11. Step 9: Full Example – Simple Web + Postgres Stack



  12. Step 10: Using the Compose File