Summary
Overview
This course session provides a hands-on introduction to Docker fundamentals, covering installation on Linux and Windows, core concepts of images and containers, and practical commands for pulling, running, stopping, and removing containers. The instructor guides learners through real-time terminal demonstrations, emphasizes best practices for command execution, and explains port mapping and container isolation. The session concludes with an overview of how containers communicate with the external world via port exposure, setting the stage for advanced topics like volumes and environment variables.
Topic (Timeline)
1. Docker Installation & Setup on Linux [00:00:09.900 - 00:03:23.160]
- Instructor guides learners through installing Docker on Ubuntu via terminal commands:
sudo apt update,sudo apt upgrade -y, and installing CA certificates. - Emphasizes copying and pasting commands one-by-one (using Ctrl+Shift+V) to avoid errors, rather than bulk pasting.
- Demonstrates verifying Docker installation with
docker --version. - Troubleshoots common learner mistakes: missing steps (e.g., skipping critical installation lines), incorrect command syntax (e.g., typing “apt” instead of “apt”), and improper spacing in commands.
- Confirms successful installation by checking Docker version output.
2. Docker Installation on Windows & Platform Differences [00:07:31.620 - 00:08:37.720]
- Contrasts Linux and Windows Docker setups: Windows users are advised to install Docker Desktop, which auto-configures the Docker engine without manual commands.
- Demonstrates Docker version check in Windows PowerShell to confirm automatic installation.
- Notes that Docker Desktop provides a richer UI and ecosystem compared to manual Linux setup.
3. Core Concepts: Images vs. Containers [00:08:37.720 - 00:11:55.860]
- Defines image as a read-only template (e.g., nginx, Apache, MySQL) created by developers and stored in container registries (e.g., Docker Hub).
- Defines container as a running instance of an image, isolated and ephemeral.
- Uses analogy: images are like software installation files; containers are like running applications.
- Clarifies that images are not stored locally until pulled; containers only exist when actively running.
- Compares Docker Hub to GitHub: images are pulled from a central registry, similar to cloning a repo.
4. Pulling, Listing, and Managing Images [00:11:59.920 - 00:16:37.120]
- Demonstrates
docker imagesto list local images (initially empty). - Pulls the
nginximage from Docker Hub usingsudo docker pull nginx. - Explains image tags: default is
ubuntu(192 MB), lightweight alternative isalpine(78 MB). - Shows how to verify image download with
sudo docker images. - Clarifies that pulling an image does not start a container — it only downloads the template.
5. Running, Stopping, and Viewing Containers [00:16:37.120 - 00:20:46.560]
- Introduces
docker runto create and start a container from an image (e.g.,sudo docker run nginx). - Explains that containers run in the foreground by default and block the terminal.
- Uses
docker psto list running containers;docker ps -ato list all containers (including stopped ones). - Demonstrates stopping a container with
docker stop <container_name_or_id>. - Clarifies that stopping a container does not delete the image — images persist on disk.
- Notes that newer Docker versions auto-run containers in detached mode; older versions require explicit
-dflag.
6. Detached Mode, Container Naming, and Management [00:20:49.000 - 00:35:07.580]
- Teaches
docker run -d(or--detach) to run containers in background. - Emphasizes using
--name <custom_name>to assign meaningful names (e.g.,--name frontend) instead of relying on auto-generated IDs. - Demonstrates starting and stopping containers by name:
docker start frontend,docker stop frontend. - Explains that container names improve usability and avoid confusion with auto-generated IDs.
- Warns against using image names (e.g.,
nginx) to stop containers — only container names or IDs work.
7. Port Mapping and Network Exposure [00:35:09.740 - 00:45:33.020]
- Explains port mapping:
-p <host_port>:<container_port>(e.g.,-p 8080:80). - Clarifies that the container’s internal service (e.g., nginx on port 80) must be exposed to a host port for external access.
- Demonstrates running nginx on host port 8080:
sudo docker run -d --name nginx-frontend -p 8080:80 nginx. - Shows accessing the service via
curl localhost:8080in terminal and browser. - Notes that ports 80, 443, and 22 are reserved; other ports (e.g., 8080, 8081) are safe for custom use.
- Compares running nginx (port 8080) and Apache (port 8081) simultaneously to illustrate multi-container port isolation.
8. Container Cleanup, Image Removal, and Best Practices [00:45:33.320 - 00:52:04.130]
- Demonstrates removing stopped containers with
docker rm <container_id>and force-deleting withdocker rm -f. - Explains that
docker rmi <image_id>removes images from disk; containers must be stopped/removed first if they depend on the image. - Guides learners to clean up all containers and images to avoid clutter.
- Advises typing commands manually (not copy-pasting) in browser to avoid confusion with Zoom shortcuts (e.g., Ctrl+Shift+C conflicts).
- Confirms successful access to web services via Firefox on custom ports (e.g.,
localhost:8080).
9. Break and Transition to Advanced Topics [00:52:07.490 - 00:53:10.390]
- Instructor announces a 10-minute break.
- Teases next topics: volumes, environment variables, and advanced networking.
Appendix
Key Principles
- Images are static templates; containers are live, isolated instances.
- Use
docker pullto download images;docker runto create containers. - Always use
--namefor containers to avoid confusion with auto-generated IDs. - Use
-p <host>:<container>to expose internal services to the host or network. - Images persist after containers are stopped; use
docker rmito delete them.
Tools Used
sudo apt update,sudo apt upgrade -y— Linux package managementdocker --version— verify installationdocker images— list local imagesdocker pull <image>— download image from registrydocker run [options] <image>— start containerdocker ps— list running containersdocker ps -a— list all containers (including stopped)docker stop <name/id>— stop containerdocker rm <name/id>— remove containerdocker rmi <image_id>— remove imagedocker run -d --name <name> -p <host>:<container> <image>— run in detached mode with port mapping
Common Pitfalls
- Typing
aptinstead ofapt(misspelling). - Forgetting
-yinapt upgrade, causing interactive prompts. - Bulk-pasting multiple commands — leads to failures if one fails.
- Using image name (e.g.,
nginx) to stop a container — must use container name or ID. - Confusing port numbers: container port (internal) vs. host port (external).
- Assuming
docker psshows all containers — usedocker ps -ato see stopped ones. - Trying to remove an image while a container based on it still exists.
Practice Suggestions
- Reinstall Docker on Linux and follow all steps from scratch.
- Run multiple containers (nginx, Apache) on different host ports and access them via browser.
- Practice naming containers meaningfully (e.g.,
web-server,db-backend). - Use
docker ps -ato inspect stopped containers, then remove them. - Try pulling different image tags (e.g.,
nginx:alpinevs.nginx:latest) and compare sizes. - Experiment with
docker run -d -p 8081:80 httpdand access vialocalhost:8081.