Docker for Developers
Containerize applications with Docker - writing Dockerfiles, Docker Compose, and deployment basics.
0 of 5 concepts completed (0%)
What You'll Learn
Tutorial Contents
1.Writing Efficient Dockerfiles
# Multi-stage build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run buildFROM node:20-alpine AS production RUN addgroup -S appgroup && adduser -S appuser -G appgroup WORKDIR /app COPY --from=builder --chown=appuser:appgroup /app/dist ./dist COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules COPY --from=builder --chown=appuser:appgroup /app/package.json . ENV NODE_ENV=production EXPOSE 3000 USER appuser CMD ["node", "dist/server.js"] ```
# .dockerignore
node_modules
.git
.env
*.log
dist
coverage
.vscode2.Docker Compose for Development
version: "3.9"
services:
api:
build: { context: ., target: builder }
ports:
- "3000:3000"
environment:
NODE_ENV: development
DATABASE_URL: postgres://postgres:secret@db:5432/myapp
volumes:
- .:/app
- /app/node_modules
command: npm run dev
depends_on:
db:db: image: postgres:16-alpine environment: POSTGRES_DB: myapp POSTGRES_PASSWORD: secret volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s retries: 5
redis: image: redis:7-alpine volumes: - redisdata:/data
volumes: pgdata: redisdata: ```
# Common commands
docker-compose up -d
docker-compose logs -f api
docker-compose exec db psql -U postgres myapp
docker-compose down -v # also remove volumesCode Example
# Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
EXPOSE 3000
USER node
CMD ["node", "server.js"]
---
# docker-compose.yml
version: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://db:5432/mydb
depends_on:
- db
db:
image: postgres:15
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:Pro Tips
- 1Use multi-stage builds to keep production images small. Build in a large image with all dev tools, copy only compiled output to a minimal runtime image.
- 2Never run containers as root. Add 'USER node' at the end of your Dockerfile most production security policies require this.
- 3Declare volumes for database data in docker-compose.yml so data persists across container restarts.
- 4Copy package.json and install dependencies BEFORE copying source code. This keeps the npm install layer cached even when source changes.
Topics Covered
Continue Learning
Explore the official documentation and deepen your knowledge with real-world practice.
Explore the Full Portfolio
This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.
The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.
For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.