DockerDevOpsContainers

Docker for Developers: A Practical Guide

Learn Docker fundamentals and how to containerize your applications effectively.

6 min read

Docker for Developers: A Practical Guide

Docker makes it easy to package and run applications in isolated containers.

Key Concepts

  • Image: Blueprint for containers
  • Container: Running instance of an image
  • Dockerfile: Instructions to build an image

Basic Dockerfile

Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]

Essential Commands

Bash
# Build an image
docker build -t myapp .

# Run a container
docker run -p 3000:3000 myapp

# List containers
docker ps

# Stop a container
docker stop <container-id>

Docker Compose

Yaml
version: '3.8'
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgres://db:5432/myapp
  db:
    image: postgres:15
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Start with Docker locally, then scale to production!

Enjoyed this article? Show some love!

1,008 views

Comments