Docker Fundamentals
Video: Day 1/40 — Docker Tutorial For Beginners — Docker Fundamentals • https://www.youtube.com/watch?v=ul96dslvVwY • Duration: ~25 min
Key terms
| Term | Meaning |
|---|---|
| Image | Read-only template (app + dependencies) used to start containers |
| Container | A running, isolated instance of an image |
| Dockerfile | The recipe that builds an image |
| Registry | A store for images (e.g. Docker Hub) |
| Layer | A cached filesystem diff that makes up an image |
| Daemon | The dockerd background service that builds and runs containers |
| Host kernel | The OS kernel shared by all containers on a host |
Problem & solution
Software that runs on one machine often breaks on another because of differing OS versions, libraries, and runtimes (the "works on my machine" problem). We need a way to package an app with everything it depends on so it runs identically everywhere.
Solution: Package an app with its dependencies into a portable image and run it as an isolated container, so it behaves the same on every machine.
The analogy
Before standardized shipping containers, dockworkers loaded loose cargo by hand: barrels, sacks, and crates of every shape, each needing custom handling and breaking in transit. The steel container changed everything, one fixed box that any crane, truck, or ship can carry the same way, sealed at the factory and opened at the destination unchanged. A Docker image is that sealed box for software: your app plus every dependency, packed once and run identically on any machine. The running box is a container. This is literally why Kubernetes calls its boxes "containers."
Why containers?
"It works on my machine" problem. A container packages app + dependencies + runtime into one portable unit that runs the same everywhere.
VM vs Container (ASCII)
VMs virtualize the hardware and run a full guest OS each; containers virtualize the OS and share the host kernel, so they are far lighter.
Core concepts
The Docker workflow is a pipeline: a Dockerfile builds an image, and an image runs as a container.
Graph legend — each node maps to a real Docker artifact/command:
| Graph node | Maps to | What it does |
|---|---|---|
| Dockerfile - recipe | the Dockerfile in your repo | Declares the steps that build the image |
| Image nginx:1.27 | docker build -t output / nginx:1.27 on Docker Hub | Read-only, layered template the container starts from |
| Container - running nginx | docker run result | A live, writable instance of the nginx image |
| Registry - Docker Hub | docker.io/library/nginx | Stores and serves images via docker pull / docker push |
- Image: read-only template (layers).
- Container: a running, writable instance of an image.
- Registry: stores/serves images (Docker Hub, ECR, GHCR...).
Docker architecture
Docker is client-server: the docker CLI sends commands over a REST API to
the daemon, which does the real work.
Graph legend — each node maps to a real Docker component:
| Graph node | Maps to | What it does |
|---|---|---|
| docker CLI | the docker command | Sends user commands to the daemon over the REST API |
| Docker Daemon - dockerd | dockerd process / /var/run/docker.sock | Does the real work: builds, runs, and manages objects |
| Images - nginx:1.27 | locally pulled nginx:1.27 | Read-only templates the daemon stores |
| Containers - web | the web container from docker run --name web | Running instances managed by the daemon |
| Networks and Volumes | docker network / docker volume objects | Connectivity and persistent storage for containers |
| Registry - Docker Hub | docker.io | Remote image store the daemon pulls from / pushes to |
Essential commands
These are the everyday commands for pulling, running, inspecting, and cleaning up containers.
docker pull nginx # download image
docker images # list local images
docker run -d --name web -p 8080:80 nginx # run detached, map ports
docker ps # running containers
docker ps -a # all (incl. stopped)
docker exec -it web bash # shell into container
docker logs web # view logs
docker stop web && docker rm web # stop + remove
docker rmi nginx # remove image
Port mapping (ASCII)
Port mapping publishes a container's internal port to a port on the host so you can reach the app from outside.
Graph legend — each node maps to the docker run -p 8080:80 nginx example:
| Graph node | Maps to | What it does |
|---|---|---|
| Host port 8080 | the 8080 in -p 8080:80 | The port published on your machine |
| Container port 80 | the 80 in -p 8080:80 | The port nginx listens on inside the container |
| curl localhost:8080 | a client request | Reaches the host port, which forwards to the container |
| nginx:1.27 inside container | the running nginx:1.27 process | Serves the response on container port 80 |
Image layers
Each Dockerfile instruction = a cached layer. Reused across builds = fast.
Graph legend — each node maps to a Dockerfile instruction / cached layer:
| Graph node | Maps to | What it does |
|---|---|---|
| CMD [nginx -g daemon off;] | the CMD instruction | Top layer: the default process the container runs |
| COPY app | a COPY instruction | Adds application files as a new layer |
| RUN apt-get install | a RUN instruction | Installs packages, cached unless the step changes |
| FROM debian - base | the FROM instruction | The base image layer every other layer stacks on |
End-to-end flow
From recipe to a reachable container: build the image, run it, pulling from a registry if needed, then map the port to the host.
Graph legend — each node maps to a real artifact/command in this flow:
| Graph node | Maps to | What it does |
|---|---|---|
| Dockerfile | the build recipe | Source for docker build |
| Image nginx:1.27 | the built/pulled image | Template the daemon runs |
| Docker Daemon dockerd | dockerd | Creates the container and pulls missing images |
| Registry Docker Hub | docker.io/library/nginx | Supplies nginx:1.27 when not cached locally |
| Container web | docker run --name web | The running nginx instance |
| Host port 8080 | -p 8080:80 | Publishes container port 80 to the host so curl localhost:8080 works |
Key takeaways
- Containers share the host kernel -> lightweight, fast to start.
- Image = build-time artifact; Container = run-time instance.
-ddetached,-p host:containerports,-itinteractive shell.
Checklist
- [ ] Ran an nginx container and hit it on localhost
- [ ] Used
exec,logs,ps,stop,rm - [ ] Understand image vs container vs registry