DevOps8 min read·

Docker Tutorial for Beginners: Containerize Your First App in 10 Minutes

Learn Docker from scratch with this beginner-friendly tutorial. Build, run, and manage containers with hands-on examples and real terminal commands.

What Is Docker and Why Does It Matter?

Docker packages your application and everything it needs into a standardized unit called a container. The same container runs identically on your laptop, a colleague's machine, or a production server.

Before Docker, the phrase "it works on my machine" caused countless deployment failures. Docker eliminates that problem entirely.

Installing Docker

macOS — Download Docker Desktop from docker.com. Drag to Applications. Done.

Windows — Install Docker Desktop. Enable WSL 2 if prompted. Restart.

Linux — Run:

sudo apt update && sudo apt install docker.io -y
sudo usermod -aG docker $USER

Log out and back in for group changes to take effect.

Your First Container

Run the hello-world container to verify your installation:

docker run hello-world

Docker downloads the image (if not cached), creates a container, runs it, and prints a success message.

Running Real Containers

Spin up an interactive Ubuntu container:

docker run -it ubuntu bash

You're now inside a full Ubuntu environment. Type exit to leave. Nothing persists — containers are ephemeral.

For a web server:

docker run -d -p 8080:80 nginx

Visit http://localhost:8080 and you'll see the Nginx welcome page.

Building Custom Images with Dockerfiles

A Dockerfile is a recipe for your image. Here's one for a Node.js app:

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Build and run:

docker build -t my-app .
docker run -d -p 3000:3000 my-app

Docker Compose for Multi-Container Apps

When your app needs multiple services (database, cache, API), Docker Compose manages them together:

services:
  api:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Run with docker compose up. Both services start together.

Essential Commands Cheat Sheet

CommandPurpose
docker psList running containers
docker imagesList local images
docker stop <id>Stop a container
docker rm <id>Remove a container
docker rmi <image>Remove an image
docker logs <id>View container output
docker exec -it <id> bashShell into a container

Next Steps

Start containerizing your own projects. Dockerize a simple app, then explore Docker Compose for multi-service architectures. From here, Kubernetes becomes the natural next step for orchestrating containers at scale.

Docker Basics

1 of 5

What is a Docker container?

Ready to practice?

Apply what you learned with free hands-on labs on XpertClass. Deploy real Docker sandboxes — no setup required.