Skip to content

Instantly share code, notes, and snippets.

@ichux
Created July 11, 2025 15:16
Show Gist options
  • Save ichux/56cf59e6c0a55527c4f4655f79794416 to your computer and use it in GitHub Desktop.
Save ichux/56cf59e6c0a55527c4f4655f79794416 to your computer and use it in GitHub Desktop.

🧩 1. Split your Compose setup

You already have docker-compose.yml, which could be your base file, and then:

  • docker-compose.dev.yml for development
  • docker-compose.prod.yml for production

Each override or extend the base. For example:

docker-compose.yml (base)

version: "3.7"

services:
  web:
    build: .
    container_name: ca.web
    ports:
      - "8018:8000"
    command: gunicorn app.wsgi:application

docker-compose.dev.yml

version: "3.7"

services:
  web:
    volumes:
      - .:/usr/src/
    command: tail -f /dev/null
    environment:
      - DEBUG=True

docker-compose.prod.yml

version: "3.7"

services:
  web:
    volumes: []  # Disable bind mount
    restart: unless-stopped
    environment:
      - DEBUG=False

πŸš€ 2. Run with a specific config

Use the -f flag to load specific files:

πŸ›  Development:

docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

🚒 Production:

docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d

You can chain multiple files; Docker will merge them in order (later files override earlier ones).


🧼 Optional: Clean up or streamline

To simplify running dev vs prod, create aliases or scripts:

run-dev.sh

#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

run-prod.sh

#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d

Make them executable:

chmod +x run-dev.sh run-prod.sh

βœ… Summary

  • Use docker-compose.yml as your base.
  • Create docker-compose.dev.yml and docker-compose.prod.yml to override volume, env, command, etc.
  • Use -f to specify the config when you run Compose.

Let me know if you'd like a template setup or want to include things like PostgreSQL or static file collection for prod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment