Skip to main content

Docker for Beginners

· One min read
Rajiv I'm
Engineer @ UseDocu

Docker has revolutionized how we build, ship, and run applications. Learn the fundamentals of containerization and how to get started with Docker.

Basic Docker Concepts​

Understanding the core components of Docker:

# Example Dockerfile
FROM node:16-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000
CMD ["npm", "start"]

Docker Commands​

Essential commands for working with Docker:

# Build an image
docker build -t myapp:latest .

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

# List running containers
docker ps

# Stop a container
docker stop container_id

Docker Compose​

Managing multi-container applications:

# docker-compose.yml
version: "3.8"
services:
web:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
depends_on:
- db

db:
image: postgres:13
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=myapp
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password

volumes:
postgres_data: