Learn

Beginner’s Guide to Docker

Docker is a platform that allows you to package an application together with everything it needs to run—such as dependencies, libraries, and configuration—into a container.

The main idea is simple:

Build once. Run anywhere.

Why Docker?

Without Docker, an application might work perfectly on your computer but fail on another machine because of different Node.js versions, Python versions, dependencies, or system configurations.

Docker solves this by creating a consistent environment for your application.

Instead of saying:

“It works on my machine.”

You can package the environment itself and run the same application almost anywhere.

Container vs Virtual Machine

This makes containers generally:

The 3 Docker Concepts You Need

The relationship is:

R

Your First Dockerfile

For a simple Node.js application:

Dockerfile
FROM node:22

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

Build the image:

Bash
docker build -t my-app .

Run it:

Bash
docker run -p 3000:3000 my-app

Your application can now be accessed through:

Code
http://localhost:3000

Useful Docker Commands

Code
docker images
Code
docker ps
Code
docker ps -a
Code
docker rm <container>
Code
docker rmi <image>

What About Docker Compose?

When an application has multiple services—such as a React frontend, Node.js API, PostgreSQL database, and Redis—running each container manually becomes inconvenient.

That's where Docker Compose comes in.

You can define your entire application stack in one configuration file:

docker-compose.yml
services:
  app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db

  db:
    image: postgres:17
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: myapp
    ports:
      - "5432:5432"

The Structure is simply:

Code
Docker Compose
│
├── app
│   └── Node.js application
│
└── db
    └── PostgreSQL

Start everything with:

Code
docker compose up

Docker Compose lets these services run together as one development environment.

When Should You Use Docker?

Docker becomes especially useful when you: