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?

Registry (Docker Hub) │ docker pull name:tag ▼ Local image store ← packages only (docker image ls) │ docker run … ▼ Container (process) ← docker ps │ stdout / stderr ▼ docker logs name ← debugging loop

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)

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.

  1. Pull an explicitly tagged image
    docker pull nginx:alpine
    Watch for Status: Downloaded newer image… or Image is up to date. You now have the package only — no container yet.
  2. List local images (see REPOSITORY + TAG)
    docker image ls
    Find nginx with tag alpine. This is what you ship and version — not a vague “nginx somewhere.”
  3. Run it (background, named, port published)
    docker run -d -p 8080:80 --name lesson2 nginx:alpine
    Same flags as lesson 1. Because you already pulled, run should not need a long download. If 8080 is busy, use -p 18080:80 instead.
  4. Confirm it’s up, then hit it
    docker ps
    open http://localhost:8080
    You should see the default nginx welcome page.
  5. Read the logs (batch)
    docker logs lesson2
    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.”
  6. Tail + follow (live stream)
    docker logs --tail 20 -f lesson2
    --tail 20 = last 20 lines, then -f keeps streaming. Refresh the browser tab a few times; new lines appear. Stop following with Ctrl+C (container keeps running). (logs options)
  7. Stop and remove
    docker stop lesson2
    docker rm lesson2
    Image nginx:alpine stays on disk (check docker image ls). Next run is instant without re-pulling.
Mental check: run without pull

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

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