Docker ComposeDeployProduction9 min read

Multi-service deploy with Docker Compose

Deploy a complete application with Docker Compose: app, database, Redis, and Nginx.


Docker Compose lets you define and run multi-container applications. Ideal for deploying a complete stack in production.

Step 1 — Install Docker and Docker Compose

If Docker is not installed:

bash
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER

Docker Compose comes included with modern Docker Engine (plugin docker compose).

Step 2 — Project structure

bash
mkdir -p ~/myapp && cd ~/myapp

Create docker-compose.yml:

yaml
version: '3.8'

services:
  app:
    build: .
    restart: always
    environment:
      - DATABASE_URL=postgres://appuser:secret@db:5432/myapp
      - REDIS_URL=redis://redis:6379
    depends_on:
      - db
      - redis
    networks:
      - backend

  db:
    image: postgres:16-alpine
    restart: always
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: appuser
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - backend

  redis:
    image: redis:7-alpine
    restart: always
    command: redis-server --requirepass redispass
    volumes:
      - redisdata:/data
    networks:
      - backend

  nginx:
    image: nginx:alpine
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
      - ./certs:/etc/nginx/certs
    depends_on:
      - app
    networks:
      - backend

volumes:
  pgdata:
  redisdata:

networks:
  backend:

Step 3 — Nginx configuration

Create nginx.conf:

nginx
server {
    listen 80;
    server_name mydomain.com;

    location / {
        proxy_pass http://app:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Step 4 — Deploy

bash
docker compose up -d
docker compose ps
docker compose logs -f app

Step 5 — Useful commands

bash
# Rebuild after changes
docker compose up -d --build

# View logs for a service
docker compose logs -f db

# Execute command in container
docker compose exec app sh

# Stop everything
docker compose down

# Stop and remove volumes (careful)
docker compose down -v

Step 6 — Update in production

bash
git pull
docker compose up -d --build app

Docker Compose simplifies deploying complex applications on your Baires Host VPS.


Was this guide helpful?