Topic 0.4
Installing Docker & Your First Command
In one line
Get Docker running on your machine and prove it works with the smallest possible container — this is the 'Hello World' every Docker journey starts with, and it's worth understanding every word of the output.
Key ideas
- 01
Docker Desktop (Windows/Mac) bundles the daemon, CLI, and a GUI into one installer — the easiest path for most developers. On Linux, you typically install the Docker Engine directly (no GUI needed, since Linux already has a native kernel with the required features).
- 02
After installing,
docker --versionconfirms the CLI is installed, anddocker infoconfirms the DAEMON is actually running and reachable — a common early mistake is having the CLI installed but the daemon not started (Docker Desktop not launched), which produces a 'Cannot connect to the Docker daemon' error. - 03
The classic first command:
docker run hello-world. This single command exercises your ENTIRE architecture from Topic 0.3: the client sends the request, the daemon checks locally (not found), pulls the tinyhello-worldimage from Docker Hub, creates a container from it, runs it (it just prints a message and exits), and the container's output appears in your terminal. - 04
Reading the hello-world output line by line teaches you the whole pull-and-run flow: it literally describes each step ('Docker Client contacted the Docker Daemon', 'the Daemon pulled the image from Docker Hub', 'the Daemon created a new container') — read it once, slowly, the first time you run it.
- 05
docker psshows RUNNING containers (empty right after hello-world, since it already exited).docker ps -ashows ALL containers including stopped ones — you'll see your hello-world container listed there with status 'Exited'. - 06
Containers are NOT deleted automatically when they stop (by default) — they just stop running, but their filesystem and metadata stick around until you
docker rmthem. This surprises beginners who expect a stopped container to simply vanish.
In your stack
- →
Once Docker is installed, the very next practical step for a Java developer is usually:
docker run -it eclipse-temurin:17-jdk bash— this drops you into a shell INSIDE a container that has a full JDK 17 installed, with zero local Java installation required on your host machine at all. Try it as your second command after hello-world.
Code & diagrams
Pick the section for your OS — you only need one of these.
# ── Windows ──────────────────────────────────────────────────
# Download and run "Docker Desktop for Windows" from docker.com,
# or install it from the command line with winget:
winget install Docker.DockerDesktop
# Requires WSL2 (Docker Desktop's installer offers to enable it for you
# if it isn't already). After installing, launch Docker Desktop from the
# Start menu and wait for the whale icon in the system tray to stop animating
# — that's your signal the daemon has finished starting.
# ── macOS ────────────────────────────────────────────────────
# Download "Docker Desktop for Mac" from docker.com, or via Homebrew:
brew install --cask docker
# Then launch Docker.app from Applications (or Spotlight) — same as Windows,
# wait for the whale icon in the menu bar to stop animating.
# ── Linux (Ubuntu/Debian example) ───────────────────────────
# Official convenience script — installs Docker Engine directly, no GUI needed:
curl -fsSL https://get.docker.com | sh
# Optional but recommended: run docker without typing sudo every time
sudo usermod -aG docker $USER
# Log out and back in (or run 'newgrp docker') for the group change to take effectRun these in order, on whichever OS you installed on. Read every line of output the first time.
# 1. Confirm the CLI is installed
docker --version
# 2. Confirm the daemon is running and reachable
docker info
# 3. The classic first container — exercises the full pull+run flow
docker run hello-world
# 4. See it in the list of ALL containers (including stopped ones)
docker ps -a
# 5. See only RUNNING containers (should be empty right now)
docker ps
# 6. Try a real, interactive container: a JDK 17 shell, no local Java needed
docker run -it eclipse-temurin:17-jdk bash
# inside the container:
java -version
exit
Explain it without notes
You run docker ps right after docker run hello-world finishes and see an EMPTY list. You then run docker ps -a and see one entry. Explain exactly why.
A teammate gets 'Cannot connect to the Docker daemon' when running any docker command. What are the two most likely causes, in order of likelihood?
Practice
Run docker run -it eclipse-temurin:17-jdk bash, then inside the container run java -version, then exit. Afterward, run docker ps -a and find this container in the list — note its exit reason.
Run docker run hello-world a SECOND time and time how much faster it feels than the first run. Explain why, using Topic 0.3's architecture.
Trade-offs
- ↔
Docker Desktop is the easiest on-ramp but consumes background resources (that hidden Linux VM on Windows/Mac) even when idle — on a resource-constrained machine, some developers prefer a lighter-weight alternative (like Colima on Mac, or running Docker Engine directly inside WSL2 on Windows) once they're past the beginner stage.
Done when you can
I have Docker installed and
docker infosucceeds without errors.I've run hello-world and can explain every line it printed.
I understand the difference between
docker psanddocker ps -a.