Technology March 05, 2026 12 min read

Docker for Beginners — From Zero to Deploying Your First App in 2026

AH
Ali Hassan
DevOps Engineer

"It works on my machine" — the four most dreaded words in software development. Docker solves this by packaging your application with everything it needs to run. Same environment everywhere: your laptop, your colleague's laptop, staging, production.

What is Docker? (Simple Explanation)

Think of Docker like a shipping container for software. Just like physical shipping containers standardized global trade (any ship can carry any container), Docker containers standardize software deployment (any server can run any container).

A Docker container includes:

  • Your application code
  • All dependencies (Node.js, Python, PHP, etc.)
  • System libraries and configurations
  • Everything needed to run — nothing more, nothing less

Docker vs Virtual Machines

  • Virtual Machines: Run a complete operating system. Heavy (GBs of storage), slow to start (minutes), resource-intensive.
  • Docker Containers: Share the host OS kernel. Lightweight (MBs), start in seconds, use minimal resources.

You can run 50+ Docker containers on a machine that could only handle 5-10 VMs.

Core Docker Concepts

Image

A blueprint for creating containers. Like a class in programming — it defines what the container will look like. Images are built from a Dockerfile.

Container

A running instance of an image. Like an object created from a class. You can run multiple containers from the same image.

Dockerfile

A text file with instructions to build an image. Here's a simple example for a Node.js app:

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

Docker Compose

A tool for defining multi-container applications. Most real apps need multiple services (web server, database, cache). Docker Compose lets you define them all in one file.

Your First Dockerfile (Step by Step)

Step 1: Create a Simple App

Create a file called server.js:

const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('<h1>Hello from Docker!</h1>');
});
server.listen(3000, () => console.log('Running on port 3000'));

Step 2: Create a Dockerfile

FROM node:20-alpine
WORKDIR /app
COPY server.js .
EXPOSE 3000
CMD ["node", "server.js"]

Step 3: Build and Run

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

Visit http://localhost:3000 — your app is running in a container!

Docker Compose: Real-World Example

Most applications need more than one service. Here's a docker-compose.yml for a web app with a database and cache:

version: "3.8"
services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgres://user:pass@db:5432/myapp
      - REDIS_URL=redis://cache:6379
    depends_on:
      - db
      - cache

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: myapp
    volumes:
      - pgdata:/var/lib/postgresql/data

  cache:
    image: redis:7-alpine

volumes:
  pgdata:

Run everything with one command: docker compose up -d

Essential Docker Commands

  • docker build -t name . — Build an image
  • docker run -p 3000:3000 name — Run a container
  • docker ps — List running containers
  • docker logs container-id — View container logs
  • docker exec -it container-id sh — Enter a running container
  • docker compose up -d — Start all services
  • docker compose down — Stop all services

Docker Best Practices

  1. Use alpine imagesnode:20-alpine is 50MB vs node:20 at 350MB
  2. Multi-stage builds — Build in one stage, run in another (smaller final image)
  3. Don't run as root — Add USER node for security
  4. Use .dockerignore — Exclude node_modules, .git, etc. from the build
  5. Pin image versions — Use node:20.11-alpine not node:latest
  6. Use volumes for data — Never store persistent data inside containers

Next Steps

Now that you understand Docker basics, explore:

  • Docker Hub — Browse thousands of pre-built images
  • CI/CD with Docker — Automate builds and deployments
  • Kubernetes — Orchestrate containers at scale (when you outgrow Docker Compose)
  • Docker Swarm — Multi-node container orchestration

Building a web application? At IOSnack, we containerize every project with Docker for consistent, scalable deployments. Let us help you modernize your infrastructure.

Tags

Docker DevOps Containers Deployment Docker Compose

Share this article

AH

Ali Hassan

DevOps Engineer

A passionate technology professional at IOSnack, dedicated to helping businesses leverage technology for growth and innovation.

Subscribe to Our Newsletter

Get the latest tech insights delivered straight to your inbox.