01

Docker Fundamentals

Video: Day 1/40 — Docker Tutorial For Beginners — Docker Fundamentals • https://www.youtube.com/watch?v=ul96dslvVwY • Duration: ~25 min

Key terms

TermMeaning
ImageRead-only template (app + dependencies) used to start containers
ContainerA running, isolated instance of an image
DockerfileThe recipe that builds an image
RegistryA store for images (e.g. Docker Hub)
LayerA cached filesystem diff that makes up an image
DaemonThe dockerd background service that builds and runs containers
Host kernelThe 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 nodeMaps toWhat it does
Dockerfile - recipethe Dockerfile in your repoDeclares the steps that build the image
Image nginx:1.27docker build -t output / nginx:1.27 on Docker HubRead-only, layered template the container starts from
Container - running nginxdocker run resultA live, writable instance of the nginx image
Registry - Docker Hubdocker.io/library/nginxStores 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 nodeMaps toWhat it does
docker CLIthe docker commandSends user commands to the daemon over the REST API
Docker Daemon - dockerddockerd process / /var/run/docker.sockDoes the real work: builds, runs, and manages objects
Images - nginx:1.27locally pulled nginx:1.27Read-only templates the daemon stores
Containers - webthe web container from docker run --name webRunning instances managed by the daemon
Networks and Volumesdocker network / docker volume objectsConnectivity and persistent storage for containers
Registry - Docker Hubdocker.ioRemote 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 nodeMaps toWhat it does
Host port 8080the 8080 in -p 8080:80The port published on your machine
Container port 80the 80 in -p 8080:80The port nginx listens on inside the container
curl localhost:8080a client requestReaches the host port, which forwards to the container
nginx:1.27 inside containerthe running nginx:1.27 processServes 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 nodeMaps toWhat it does
CMD [nginx -g daemon off;]the CMD instructionTop layer: the default process the container runs
COPY appa COPY instructionAdds application files as a new layer
RUN apt-get installa RUN instructionInstalls packages, cached unless the step changes
FROM debian - basethe FROM instructionThe 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 nodeMaps toWhat it does
Dockerfilethe build recipeSource for docker build
Image nginx:1.27the built/pulled imageTemplate the daemon runs
Docker Daemon dockerddockerdCreates the container and pulls missing images
Registry Docker Hubdocker.io/library/nginxSupplies nginx:1.27 when not cached locally
Container webdocker run --name webThe running nginx instance
Host port 8080-p 8080:80Publishes 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.
  • -d detached, -p host:container ports, -it interactive shell.

Checklist

  • [ ] Ran an nginx container and hit it on localhost
  • [ ] Used exec, logs, ps, stop, rm
  • [ ] Understand image vs container vs registry