Summary

Overview

This course session provides a comprehensive, hands-on introduction to Docker fundamentals, including container management, image creation, Dockerfiles, Docker Compose, volumes, and networking. The trainer guides learners through practical labs covering pulling and running images, inspecting containers, creating custom images via Dockerfiles, deploying multi-container applications with Docker Compose, managing persistent storage with volumes, and configuring user-defined networks. The session includes extensive live demonstrations, troubleshooting guidance, and interactive Q&A, culminating in a lab on inter-network container communication using Docker Network Connect. The content is structured to build foundational DevOps and containerization skills for enterprise use cases.

Topic (Timeline)

1. Docker Command Fundamentals and System Inspection [00:00:15 - 00:04:19]

  • Introduction to core Docker commands: docker, docker run --help, docker images --help, docker info.
  • Explanation of Docker client-server architecture and key output fields from docker info (version, architecture, logs, storage driver).
  • Location of Docker data: /var/lib/docker — where images, volumes, and configuration files are stored by default.
  • Confirmation of understanding via Q&A: “Any questions team?”
  • Transition to lab: Introduction to Module 1 Lab 2 — creating containers from pulled images.

2. Container Creation, Access, and File Operations [00:04:22 - 00:19:35]

  • Lab 2 workflow: Pull indynext image → list with docker images → run container in detached mode (docker run -d indynext:latest) → verify with docker ps.
  • Logging into containers: docker exec -it <container_id> bash.
  • Exploring container filesystem: find, navigating to application files (e.g., index.html).
  • Installing tools inside containers: apt updateapt install vim.
  • Editing files with vi: entering insert mode (i), saving and exiting (Esc:wq).
  • Exiting container without stopping: Ctrl+P+Q.
  • Stopping and restarting containers: docker stop, docker start, and verifying file persistence across restarts.

3. Image Commitment and Pushing to Docker Hub [00:20:14 - 00:33:39]

  • Committing container changes to a new image: docker commit <container_id> IMG01.
  • Tagging the image for Docker Hub: docker tag IMG01:latest <username>/<repo>:latest.
  • Authenticating with Docker Hub: docker login (username/password).
  • Pushing image: docker push <username>/<repo>:latest.
  • Verifying push via Docker Hub web interface.
  • Pulling and testing a shared image: docker pull <username>/<repo>:latest → run container → verify file contents.
  • Troubleshooting: ASR errors corrected silently (e.g., “CK” → “OK”, “apd” → “apt”), command syntax guidance.

4. Building Custom Images with Dockerfile [00:41:27 - 00:55:35]

  • Introduction to Dockerfile: purpose, structure, and key instructions (FROM, COPY, ADD, RUN, CMD, EXPOSE).
  • Creating a project directory (mkdir project1) and writing a Dockerfile for Apache.
  • Building image: docker build -t img02 . (dot = current directory).
  • Exposing port 80 in Dockerfile and during container run (-p 80:80).
  • Network configuration issue: port 80 blocked on VM; instructor escalates to backend team to enable all traffic in security group.
  • Testing web server: curl <public_ip> — output expected but blocked until firewall fix.

5. Modifying Running Containers and Re-Pushing [00:55:35 - 01:18:12]

  • After firewall fix, confirming Apache page accessible via browser and curl.
  • Logging into running container: docker exec -it <container_id> bash.
  • Modifying web content: apt install vim → edit /var/www/html/index.html → save with :wq.
  • Real-time observation: browser refresh shows updated content.
  • Re-tagging and re-pushing modified image to Docker Hub: docker tag img02 <username>/<repo>:latestdocker push.

6. Docker Compose: Multi-Container Applications [01:21:08 - 01:38:11]

  • Introduction to Docker Compose: managing multi-container apps (e.g., WordPress + MySQL).
  • Installing Docker Compose: downloading binary, setting execute permissions.
  • Creating docker-compose.yaml: defining services (db, wordpress), volumes, environment variables, dependencies, and port mappings.
  • Running stack: docker-compose up -d — pulls images, creates containers, sets up network.
  • Verifying: docker-compose images, docker-compose ps, docker-compose logs.
  • Stopping and removing: docker-compose down (keeps volumes) vs. docker-compose down -v (removes volumes).
  • Locating persistent volumes: /var/lib/docker/volumes/<project>_db_data/_data.
  • Emphasis on template reusability for dev/test/prod environments.

7. Docker Volumes: Types and Management [01:42:34 - 01:47:42]

  • Three volume types: bind mounts, tmpfs, and Docker-managed volumes.
  • Bind mounts: host path → container path (OS-dependent, e.g., /tmp).
  • tmpfs: in-memory storage (ephemeral, Linux-only, no disk I/O).
  • Docker-managed volumes: created under /var/lib/docker/volumes/, OS-agnostic, persistent, shareable, better performance.
  • Commands: docker volume create <name>, docker run -v <volume_name>:/path/in/container, docker inspect <volume_name>.
  • Volume lifecycle: remove only after container deletion.
  • Instructor assesses need for hands-on lab; learners indicate no need, so lab skipped.

8. Docker Networking: Default and User-Defined Networks [01:47:47 - 02:03:57]

  • Default networks: bridge, host, none — list with docker network ls.
  • Bridge network details: subnet 172.17.0.0/16, gateway 172.17.0.1, containers assigned IPs (e.g., .2, .3, .4).
  • Container connectivity: containers on same bridge network can ping each other.
  • Inspecting network and container: docker network inspect bridge, docker inspect <container_id> → view IP/MAC/gateway.
  • User-defined networks: create custom subnet/gateway: docker network create --subnet=192.168.0.0/16 --gateway=192.168.0.1 network1.
  • Attaching containers to custom networks: docker run -d --name new --network network1 nginx.
  • Inter-network communication: containers on different networks cannot communicate by default.
  • Solution: docker network connect <network_name> <container_id> — adds secondary IP to container, enabling cross-network access.
  • Lab 8: create two bridge networks (bridge1, bridge2), run containers in each, use docker network connect to enable ping between them.

Appendix

Key Principles

  • Container Persistence: Data survives container restarts if stored in volumes or filesystems, but not in ephemeral containers.
  • Image vs. Container: Images are templates; containers are running instances. Changes to containers can be committed to new images.
  • Dockerfile Best Practice: Use COPY over ADD unless remote URL extraction is needed; specify explicit base images (e.g., ubuntu:20.04).
  • Docker Compose: Declarative YAML for multi-container apps; enables environment consistency (dev/test/prod).
  • Network Isolation: Default bridge network allows intra-network communication; inter-network requires explicit docker network connect.

Tools Used

  • docker CLI: core commands (run, ps, images, exec, commit, build, tag, push, pull, inspect, network, volume)
  • vi/vim: text editor inside containers
  • apt: package manager (Ubuntu/Debian)
  • curl: HTTP client for testing web services
  • ping: network connectivity test
  • docker-compose: orchestration tool
  • ifconfig/ip addr: network interface inspection

Common Pitfalls

  • Command Syntax Errors: Missing spaces, incorrect flags (e.g., -p 80:80 vs. -p 80 80), wrong capitalization (Docker vs docker).
  • File Permissions: Docker Compose YAML must be properly formatted (no tabs, correct indentation, no double quotes from copy-paste).
  • Network Access: Port blocked by cloud security groups — must be explicitly opened (e.g., HTTP on port 80/8000).
  • Container State Confusion: docker ps shows only running containers; use docker ps -a to see stopped ones.
  • Volume Misunderstanding: docker-compose down without -v leaves data; users may assume data is gone when it’s not.
  • Login/Exit Confusion: exit stops container; Ctrl+P+Q detaches without stopping.

Practice Suggestions

  • Rebuild the Apache Dockerfile from scratch without reference.
  • Create a custom image with Python and a simple Flask app, then push to Docker Hub.
  • Use Docker Compose to deploy a Redis + Node.js app with named volumes.
  • Create two user-defined networks and connect a container to both — verify connectivity with ping.
  • Practice docker inspect on containers, networks, and volumes to understand their JSON structure.