Run docker compose ps or docker ps to see what is actually running.
Docker Fundamentals
Learn Docker in a simple order: understand the idea, run the command, break it down in plain English, practice it, then use everything in a real Node.js + PostgreSQL project.
Small explanations. Real commands. One checkpoint at a time.
Every lesson follows the same pattern so beginners know exactly what to do next. Do not memorize commands blindly—understand what they are asking Docker to do.
Understand Docker first
Learn the mental model, run your first containers, map ports and inspect what Docker is doing.
1.1Docker, images and containers
Concept
Docker packages an application with the environment it needs and runs it inside an isolated container.
Command / code
docker version docker run hello-world
Breakdown
- docker version → checks that the Docker CLI can communicate with the Docker Engine.
- docker run → creates a new container from an image and starts it.
- hello-world → a tiny image used to prove Docker works.
Plain English: Docker, show me that your client and engine work, then download and run the small hello-world test container.
Why it matters
This gives you the basic mental model before you start memorizing commands.
Checkpoint: Run both commands. Your checkpoint is seeing the hello-world success message.
1.2See what is running
Concept
Images are reusable blueprints. Containers are instances created from those images.
Command / code
docker ps docker ps -a docker images
Breakdown
- docker ps → shows containers currently running.
- docker ps -a → also shows stopped containers.
- docker images → shows images stored on your machine.
Plain English: Docker, show me my running containers, all containers, and the image blueprints stored locally.
Why it matters
These are the first commands you use when you need to understand the current Docker state.
Checkpoint: Run the three commands and identify at least one image and one container.
1.3Run a real web container
Concept
Port mapping lets a service inside a container become reachable from your laptop.
Command / code
docker run -d --name my-nginx -p 8081:80 nginx
Breakdown
- -d → detached/background mode.
- --name my-nginx → gives the container a readable name.
- -p 8081:80 → maps laptop port 8081 to port 80 inside the container.
- nginx → the image Docker uses to create the container.
Plain English: Docker, create an Nginx container, call it my-nginx, run it in the background, and make it available through localhost:8081.
Why it matters
Port mapping is one of the first concepts you need for APIs, databases and multi-service applications.
Checkpoint: Open http://localhost:8081. You should see the Nginx page.
1.4Logs, inspect and enter a container
Concept
When a container behaves unexpectedly, inspect evidence before changing things.
Command / code
docker logs my-nginx docker inspect my-nginx docker exec -it my-nginx sh
Breakdown
- docker logs → shows application output from the container.
- docker inspect → shows detailed container configuration.
- docker exec -it ... sh → opens a shell inside an already-running container.
Plain English: Docker, show me what this container has been saying, show me its configuration, then let me inspect it from the inside.
Why it matters
This is the beginning of debugging Docker instead of guessing.
Checkpoint: Enter the Nginx container, run pwd and ls, then exit.
Build your own container
Move from using public images to packaging a small Node.js application yourself.
2.1Write your first Dockerfile
Concept
A Dockerfile is the recipe Docker follows to build your application image.
Command / code
FROM node:22-slim WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . EXPOSE 3000 CMD ["node", "server.js"]
Breakdown
- FROM → choose the base image.
- WORKDIR → choose the working folder inside the image.
- COPY package*.json + RUN npm ci → install dependencies in a cache-friendly layer.
- COPY . . → copy the application source.
- CMD → start the app when the container starts.
Plain English: Docker, start with Node.js, create an app folder, install my exact dependencies, copy my code, document port 3000, and start server.js when a container runs.
Why it matters
Dockerfiles make your application environment repeatable instead of depending on manual laptop setup.
Checkpoint: Create a small Node/Express app and place this Dockerfile beside package.json.
2.2Build and run your image
Concept
docker build turns a Dockerfile into an image. docker run creates a container from that image.
Command / code
docker build -t day2-node-app . docker run -d --name day2-node-container -p 3000:3000 day2-node-app
Breakdown
- -t day2-node-app → names/tags the image.
- . → use the current directory as the build context.
- -p 3000:3000 → map host port 3000 to container port 3000.
Plain English: Docker, build my app into an image from this folder, then create a background container from it and expose the app on port 3000.
Why it matters
This is the core containerization workflow you will reuse on real backend applications.
Checkpoint: Build the image, run the container and verify your Node endpoint works in the browser or API client.
2.3Docker Compose
Concept
Compose moves long runtime settings into one reusable YAML file.
Command / code
services:
app:
build: .
ports:
- "3000:3000"
# then run
docker compose up -d --build
docker compose psBreakdown
- services → the containers/services in this project.
- build: . → build the app from the local Dockerfile.
- ports → map the host and container ports.
- up -d --build → rebuild if needed and start in the background.
Plain English: Docker Compose, read my service configuration, build the app, start it in the background, and then show me whether it is running.
Why it matters
Compose becomes especially useful when an application needs more than one service.
Checkpoint: Move your Node app from docker run commands into compose.yaml and start it with Compose.
2.4Environment configuration
Concept
Environment variables keep settings such as ports and database details outside source code.
Command / code
PORT=3000
HOST_PORT=5000
# compose.yaml
ports:
- "${HOST_PORT}:${PORT}"Breakdown
- PORT → the port used inside the application/container.
- HOST_PORT → the port exposed on your laptop.
- ${...} → Compose substitutes values from the environment/.env file.
Plain English: Use configuration values from outside the source code so the same app can run with different settings without rewriting the application.
Why it matters
This is how development, staging and production environments can use different configuration safely.
Checkpoint: Change HOST_PORT, recreate the service, and confirm the app moves to the new host port.
Connect real services
Add PostgreSQL, persistence, Docker networking and finish with the real Docker Student API repository.
3.1Networks and service names
Concept
Containers on the same Compose network can communicate using service names instead of changing IP addresses.
Command / code
DB_HOST=db DB_PORT=5432
Breakdown
- db → the PostgreSQL service name in compose.yaml.
- 5432 → PostgreSQL port inside the Docker network.
- localhost inside the Node container would point back to the Node container itself.
Plain English: Node, connect to the PostgreSQL container using the Docker service name db instead of trying to find it through localhost.
Why it matters
Understanding container-to-container networking is essential for multi-service systems.
Checkpoint: Inspect the Compose network and confirm both app and database services are attached.
3.2Persistent PostgreSQL data
Concept
Containers are replaceable. Database data should live separately so it can survive container recreation.
Command / code
services:
db:
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:Breakdown
- postgres_data → a named Docker volume.
- /var/lib/postgresql/data → PostgreSQL data directory inside the container.
- top-level volumes → tells Compose to manage the named volume.
Plain English: Docker Compose, keep PostgreSQL data in a named storage area outside the disposable database container.
Why it matters
Without persistence, recreating a database container could remove the data you need.
Checkpoint: Add one student, run docker compose down, start the project again and verify the record still exists.
3.3Health checks and safe startup
Concept
A running database process is not always ready to accept connections yet.
Command / code
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 5Breakdown
- pg_isready → asks PostgreSQL whether it is ready.
- interval → how often Docker checks.
- timeout → how long each check may take.
- retries → how many failures before unhealthy.
Plain English: Docker, keep checking PostgreSQL until it is actually ready, not merely running as a process.
Why it matters
This reduces startup races where the API starts before the database can accept connections.
Checkpoint: Run docker compose ps and confirm the PostgreSQL service reaches healthy status.
3.4Clone and run the final project
Concept
The final checkpoint is being able to run and explain a complete Node.js + PostgreSQL Docker Compose project.
Command / code
git clone https://github.com/Mrbarnx/docker-student-api.git cd docker-student-api docker compose up -d --build docker compose ps
Breakdown
- git clone → copy the learning repository to your computer.
- up -d --build → build/start the complete stack.
- compose ps → verify student-api and student-db status.
Plain English: Download the Docker Student API project, enter it, build and start every service, then check that the application and database are running.
Why it matters
Real understanding comes from reproducing the complete system, not only reading Docker definitions.
Checkpoint: Test GET /health, GET /students and POST /students, then explain the architecture in your own words.
Docker Student API
Clone a real Node.js/Express REST API that runs with PostgreSQL through Docker Compose. The project demonstrates container networking, persistent volumes, environment configuration, health checks, automatic database initialization and parameterized SQL queries.
Client / Browser
↓
localhost:5001
↓
Node.js + Express container
↓
Docker custom network
↓
PostgreSQL container
↓
Named PostgreSQL volumeRead the error. Then change one thing.
The guide teaches an evidence-first debugging loop instead of randomly reinstalling Docker or changing unrelated configuration.
Use docker compose logs app or docker logs before guessing.
Use docker compose config, then verify ports, environment values and service names.
Fix only what the evidence supports, run the failing step again, and confirm the result.
Skills you can honestly say you practiced.
Only claim the ones you can explain and demonstrate. Docker knowledge alone does not make someone a DevOps Engineer.
Before you say you know Docker.
You should be able to explain these without blindly reading from the guide.
Explain the reusable blueprint versus the running/stopped instance.
Explain host port vs container port and why conflicts happen on the host.
Explain why the API uses db instead of localhost.
Demonstrate that database records survive container recreation because of a named volume.
Keep the detailed guide.
The learning page is intentionally simplified. Download the Markdown reference for the deeper 5-day sprint notes, complete command reference, debugging examples and interview preparation.