Docker for Developers — Containers Made Simple

Learn Docker fundamentals: images, containers, Dockerfiles, docker-compose, and containerizing your applications.

General Beginner 📖 10 min

Core Concepts

  • Image: Blueprint for a container (like a class)
  • Container: Running instance of an image (like an object)
  • Dockerfile: Instructions to build an image
  • Volume: Persistent data storage

Basic Dockerfile

# Node.js example
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Docker Commands

# Build an image
docker build -t my-app .

# Run a container
docker run -p 3000:3000 my-app

# List running containers
docker ps

# Stop a container
docker stop <container-id>

# View logs
docker logs <container-id>

# Execute command in running container
docker exec -it <container-id> sh

Docker Compose

# docker-compose.yml
version: '3.8'
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=mongodb://mongo:27017/myapp
    depends_on:
      - mongo
  
  mongo:
    image: mongo:6
    ports:
      - "27017:27017"
    volumes:
      - mongo-data:/data/db

volumes:
  mongo-data:

Useful Commands

docker-compose up -d          # Start services in background
docker-compose down            # Stop and remove services
docker-compose logs -f app     # Follow logs
docker-compose exec app sh     # Shell into container

Ready to Level Up Your Coding Skills?

Join Coderz Club and learn to code with challenges, battles, and an AI mentor.

Join Coderz Club Free →