Docker Compose – Run Multi-Container Apps Easily

πŸ“Œ Quick Summary
    🧱 Table of Contents

    Running a single container is easy…
    But what if your app needs:

    • Database
    • Backend
    • Frontend

    That’s where Docker Compose comes in.

    πŸ”Ή What is Docker Compose?

    Docker Compose lets you define and run multi-container applications using a simple YAML file.

    πŸ”Ή Install Docker Compose

    sudo apt install docker-compose-plugin

    Verify:

    docker compose version

    πŸ”Ή Example: Run Nginx with One File

    Create a file:

    nano docker-compose.yml

    Paste this:

    version: '3.8'
    
    services:
      web:
        image: nginx:latest
        container_name: my-nginx
        ports:
          - "8080:80"
        restart: unless-stopped

    πŸ”Ή Start the App

    docker compose up -d

    Now open:

    http://your-server-ip:8080

    πŸ”Ή Stop the App

    docker compose down

    πŸ”Ή Example: App + Database

    version: '3.8'
    
    services:
      app:
        image: node:18
        working_dir: /app
        volumes:
          - ./app:/app
        command: npm start
        ports:
          - "3000:3000"
    
      db:
        image: mysql:8
        environment:
          MYSQL_ROOT_PASSWORD: root
          MYSQL_DATABASE: test
        volumes:
          - db_data:/var/lib/mysql
    
    volumes:
      db_data:

    πŸ”Ή Why Use Docker Compose?

    • 🧠 Simple configuration
    • πŸ” One command to start everything
    • πŸ“ Easy to version control
    • πŸš€ Perfect for development & production

    πŸ”Ή Pro Tips (Advanced)

    • Use .env file for secrets
    • Always use restart: unless-stopped
    • Use volumes for persistence
    • Keep services isolated

    πŸ”Ή Conclusion

    With Docker Compose you can:

    • Run full apps with one command
    • Manage services easily
    • Scale your infrastructure

    Leave a comment

    Your email address will not be published. Required fields are marked *