Docker · Lesson 0002
Pull, tags, and the logs loop
Know what you downloaded, which version it is, and how to read what a container printed — the three habits behind “why is this broken?”
Mission link: Reliable shipping means controlling which image you run (tags) and debugging the running unit (logs) with the CLI. Production will not open Desktop for you.
Continues lesson 0001 · cheat sheet first-run CLI
Three jobs, three commands
docker pull
Download an image (package) from a registry into your machine. No process starts. You only store the template.
docker run
Create and start a container from an image. If the image is missing locally, Docker pulls it first — then runs.
docker logs
Print what the container wrote to stdout/stderr. This is the first place you look when a service “is up” but misbehaves. (docker logs reference)
pull = buy the recipe book · run = cook a meal · logs = taste / read the kitchen ticket. You can buy without cooking; cooking without the book triggers a store run (auto-pull).
Pull behavior: docker image pull · image mental model: What is an image?
Tags: the version label on the package
An image reference is usually name:tag. If you omit the tag,
Docker uses latest. That word is just a default label — it is
not a guarantee of “newest forever.” Maintainers can move
latest to a new build at any time.
(pull docs)
nginx:alpine— nginx image, tagalpine(small Linux base).node:22— Node major version as tag (common for TypeScript apps).nginx— same asnginx:latest.
For shipping, prefer explicit tags you intend (e.g.
node:22-alpine) so local, CI, and prod share the same label.
Digests (@sha256:…) pin immutably — later lesson when you
harden deploys.
Check: pull vs run, and tags
What does docker pull nginx:alpine do?
In nginx:alpine, what is alpine?
Skill: pull → list → run → logs → clean
Do this in your terminal. Engine must be running (Docker Desktop open if that’s how you start the daemon). Use a small official image so the pull is quick.
-
Pull an explicitly tagged image
Watch fordocker pull nginx:alpineStatus: Downloaded newer image…orImage is up to date. You now have the package only — no container yet. -
List local images (see REPOSITORY + TAG)
Finddocker image lsnginxwith tagalpine. This is what you ship and version — not a vague “nginx somewhere.” -
Run it (background, named, port published)
Same flags as lesson 1. Because you already pulled, run should not need a long download. If 8080 is busy, usedocker run -d -p 8080:80 --name lesson2 nginx:alpine-p 18080:80instead. -
Confirm it’s up, then hit it
You should see the default nginx welcome page.docker ps open http://localhost:8080 -
Read the logs (batch)
Access lines appear after you opened the page. Logs are stdout/stderr captured from the container process — gold for “it won’t start” and “it started but fails requests.”docker logs lesson2 -
Tail + follow (live stream)
docker logs --tail 20 -f lesson2--tail 20= last 20 lines, then-fkeeps streaming. Refresh the browser tab a few times; new lines appear. Stop following with Ctrl+C (container keeps running). (logs options) -
Stop and remove
Imagedocker stop lesson2 docker rm lesson2nginx:alpinestays on disk (checkdocker image ls). Next run is instant without re-pulling.
Delete nothing yet — just know that
docker run … some-image:tag will auto-pull if the image is
absent. Explicit docker pull is still useful: fail fast on
registry issues, warm CI caches, and make “what version did we download?”
obvious before you start processes.
Check: the debugging loop
A container is running but pages fail. First CLI look?
After docker stop + rm of lesson2, what remains?
Why this matters for shipping
- Local: pull once, run many times; tags keep Node/nginx versions honest.
- Reliable: same
name:tagin dev and deploy reduces “works on my machine.” - Maintain:
docker logs/logs -fis how you investigate failures without a GUI. - Secure (preview): knowing the exact tag (and later digest) is how you control what actually runs.
Primary source (read this next)
What is an image? — Docker Docs (official)
Do the CLI sections on pull and listing images. For log flags, keep docker logs open as a reference while you practice.
Quick reference (commands from this lesson)
docker pull nginx:alpine
docker image ls
docker run -d -p 8080:80 --name lesson2 nginx:alpine
docker ps
docker logs lesson2
docker logs --tail 20 -f lesson2
docker stop lesson2
docker rm lesson2