diff --git a/machines/guides-examples/multi-container-machines.html.markerb b/machines/guides-examples/multi-container-machines.html.markerb index 9829332171..517b70299a 100644 --- a/machines/guides-examples/multi-container-machines.html.markerb +++ b/machines/guides-examples/multi-container-machines.html.markerb @@ -140,6 +140,105 @@ Containers in a Machine share the same kernel and VM, but are isolated at the pr There are several ways to deploy multi-container machines on Fly.io. Choose the method that best fits your workflow: +### Using Docker Compose + +If you already have a Docker Compose setup, you can deploy it to Fly Machines without rewriting your configuration. Fly builds and runs Compose services as containers within a single Machine. + +#### Requirements + +You need flyctl v0.3.152 or later: + +```bash +fly version +``` + +If you're behind, update with `fly version update`. + +#### Configuration + +Add a `[build.compose]` section to your `fly.toml`: + +```toml +[build.compose] +``` + +Fly auto-detects Compose files using the standard lookup order: `compose.yaml`, `compose.yml`, `docker-compose.yaml`, `docker-compose.yml`. If your file has a different name, specify it: + +```toml +[build.compose] +file = "docker-compose.prod.yml" +``` + +#### Routing traffic + +Set `internal_port` in your `fly.toml` `[[services]]` or `[http_service]` block to match the port exposed by the container that should receive traffic. Only one container handles inbound requests from the Fly proxy. + +```toml +[http_service] + internal_port = 8080 + force_https = true +``` + +#### Example + +A web service with a Redis sidecar, both running in the same Machine. `fly deploy` builds the `web` service from a `Dockerfile` in your project directory; `redis` runs as a pre-built sidecar. + +**Dockerfile:** + +```dockerfile +FROM nginxdemos/hello:plain-text +``` + +**compose.yml:** + +```yaml +services: + web: + build: . + ports: + - "80:80" + + redis: + image: redis:latest +``` + +**fly.toml:** + +```toml +app = "my-compose-app" +primary_region = "ord" + +[build.compose] + +[http_service] + internal_port = 80 + force_https = true + auto_stop_machines = "stop" + auto_start_machines = true + +[[vm]] + size = "shared-cpu-1x" + memory = "512mb" +``` + +Deploy with: + +```bash +fly deploy +``` + +The `web` container handles inbound traffic on port 80, and the `redis` container runs alongside it as a sidecar. Your application code can reach Redis at `localhost:6379` because both containers share the same network namespace inside the Machine. + +