Table of Contents

Docker Compose

Docker Compose is a powerful tool that streamlines the process of defining and managing multi-container Docker applications. It allows you to use a YAML file to configure your application's services, networks, and volumes. With a single command, you can create and start all the services from your configuration, making it ideal for development, testing, and staging environments.

Key Features

Benefits

Code Examples

1. **Simple Web Application with Database:**

```yaml version: '3' services:

 web:
   build: .
   ports:
     - "5000:5000"
   depends_on:
     - db
 db:
   image: postgres:latest
   environment:
     POSTGRES_PASSWORD: mysecretpassword
```

This `docker-compose.yml` file defines two services: a `web` service that builds from the current directory and exposes port 5000, and a `db` service that uses the latest PostgreSQL image.

2. **Scaling a Service:**

```bash docker-compose up -d –scale web=3 ```

This command starts the application in detached mode and scales the `web` service to 3 replicas.

3. **Viewing Logs:**

```bash docker-compose logs -f web ```

This command follows the logs of the `web` service in real-time.

Additional Resources