Hands-on Lab

#Lab: Docker Container Deployment

Build and deploy a containerized application.

#🎯 Objectives

  • Build a Docker image
  • Run container with networking
  • Use Docker Compose

#Task 1: Build Image

dockerfile
1# Dockerfile
2FROM node:20-alpine
3WORKDIR /app
4COPY package*.json ./
5RUN npm ci --only=production
6COPY . .
7EXPOSE 3000
8CMD ["node", "server.js"]
bash
docker build -t myapp:1.0 .

#Task 2: Run Container

bash
1docker run -d \
2  --name myapp \
3  -p 3000:3000 \
4  -e NODE_ENV=production \
5  myapp:1.0

#Task 3: Docker Compose

yaml
1version: '3.8'
2services:
3  app:
4    build: .
5    ports:
6      - "3000:3000"
7    depends_on:
8      - db
9  db:
10    image: postgres:15
11    environment:
12      POSTGRES_PASSWORD: secret
bash
docker compose up -d

#✅ Success Criteria

  • Image built successfully
  • Container runs on port 3000
  • Compose stack works