# Add Compose Profiles for Optional Services

Yes. An agent moves optional tooling such as pgAdmin behind a Compose profile so docker compose up starts only core services, verifies both modes, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-compose-profiles/docker-compose/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the Compose file and the README to find which services are the application and which are tools someone sometimes wants. In a sample like `postgresql-pgadmin` in docker/awesome-compose, `compose.yaml` defines two services: `postgres` from `postgres:latest`, with `POSTGRES_USER`, `POSTGRES_PASSWORD` and `POSTGRES_DB` read from the `.env` file and port `5432` published, and `pgadmin` from `dpage/pgadmin4:latest`, with `PGADMIN_DEFAULT_EMAIL` and `PGADMIN_DEFAULT_PASSWORD` from the same file and port `5050` mapped to `80`. Both have `restart: always`, both carry a fixed `container_name`, and neither declares `depends_on`. The README's deploy section shows `docker compose up` starting both and then walks through registering the database inside pgAdmin by its service name.

pgAdmin is a tool for a person, not a dependency of the database, so the agent gives it `profiles: ["tools"]` and a `depends_on` on `postgres`. With that, `docker compose up` starts only `postgres`; `docker compose --profile tools up`, or `COMPOSE_PROFILES=tools` in the environment or the `.env` file, starts both; and naming the service directly, as in `docker compose up pgadmin`, enables its profile on its own and brings `postgres` with it through `depends_on`. The agent rewrites the README's deploy section around those three commands, including how to stop a stack that was started with the profile, and leaves the pgAdmin connection walkthrough as it is.

The sandbox has no Docker preinstalled, so the agent installs it with `sudo apt-get install -y docker.io`, starts `dockerd`, and uses `docker-compose` v1 from that package set, since Compose v2 is not in it. `docker-compose config` prints the merged file so the profile shows where it should; `docker-compose up -d` followed by `docker-compose ps` shows one container; `docker-compose --profile tools up -d` shows two, with `pg_isready` answering on `postgres` and `curl` fetching pgAdmin's login page on `5050`. The agent writes every command it documents into the README only after it has run it.

Because the repository holds many samples, the pull request stays inside this one directory and follows `CONTRIBUTING.md`: the sample's own README explains the change, and the global list is untouched because no sample was added. Where a sample has more than one optional service, the same profile name groups them, and a service that belongs to two profiles lists both.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add Compose profiles to this sample so optional tooling starts only on request. Read compose.yaml, .env and README.md in the sample first. Put pgadmin behind a tools profile with a depends_on on postgres, so docker compose up starts only postgres, docker compose --profile tools up or COMPOSE_PROFILES=tools starts both, and docker compose up pgadmin enables the profile by naming the service. Install Docker in the sandbox, start dockerd, and verify with docker-compose config, docker-compose up -d and docker-compose ps in both modes, with pg_isready against postgres and curl against pgAdmin's login page. Rewrite the README's deploy section around the commands you ran, including how to stop a stack started with the profile, keep the pgAdmin connection walkthrough, change nothing outside this sample's directory, and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch with two changed files: `compose.yaml`, where `pgadmin` gains `profiles` and `depends_on`, and `README.md`, whose deploy section now lists the plain command, the profile command and the environment variable, and says how to stop the stack in each case. The `.env` file, the image tags and the published ports are unchanged.

The description pastes `docker-compose ps` for both modes, the `pg_isready` line and the `curl` status for the pgAdmin page, so a reviewer sees that the database runs alone and that the tool still reaches it when asked for. The transcript at `GET /o/{org}/sessions/{id}/messages` keeps the Docker install, the `config` output and every `up`, `ps` and `down` with its result.

Before merging, a reviewer decides whether `tools` is the profile name their other projects use, whether pgAdmin should also lose `restart: always` now that it is optional, and whether the fixed `container_name` values should stay. One follow-up message to the same session applies the same pattern to another sample in the repository.

## Run it on every Compose file with optional tooling

A developer who keeps starting a database admin tool they rarely use starts one run from the terminal with this prompt and the repository, and gets a pull request back with the profile and the verified commands. The run's sandbox installs Docker and runs the stack, so the README describes what happened rather than what should.

A platform team can send one `POST /o/{org}/sessions` per Compose project; `GET /o/{org}/github` lists the repositories the Rush GitHub App installation reaches, and a script can start a run wherever a `compose.yaml` contains a service whose image is an admin UI. Each run reads its own file, so a project whose tool is a mail catcher gets a profile for that.

## Why run it on Rush?

Profiles are a small change with sharp edges: a service left out of `depends_on` starts alone, a `down` without the profile can leave a container behind, and a README that was not run against the file sends people to a command that does nothing. The agent runs each command in its own sandbox with a Docker daemon it installed for the purpose, and writes down only what it saw.

The pull request carries that record: the merged config, the `ps` output in both modes and the checks against each service are in the transcript beside the commands. Several Compose projects can be handled at once, each in its own sandbox with its own daemon, with one pull request each.

## Frequently asked questions

### Does docker compose up pgadmin still work without the flag?

Yes. Naming a service on the command line enables the profiles it belongs to, and the `depends_on` the agent adds makes Compose start `postgres` first. The README documents that form beside `--profile tools` and `COMPOSE_PROFILES=tools` so each person uses the one they prefer.

### What happens to the running pgAdmin container on docker compose down?

The agent runs `down` in both modes in the sandbox and writes the result into the README, including the form with the profile flag, so the instructions match what Compose does rather than what a reader assumes.

### Can several tools share one profile?

Yes. A profile is a name, and any number of services can list it; a service can list several profiles too. In a sample with an admin UI and a mail catcher, both would carry `tools`, and the same `--profile tools` starts them together.

### Why install Docker in the sandbox instead of only editing YAML?

Because the YAML is easy and the behaviour is the point. Without running `up` and `ps` in both modes, nobody knows whether `depends_on` fired or whether the stop command leaves a container behind, and the README would be a guess. The sandbox has no Docker by default, so the agent installs it and starts `dockerd` first.

## More Docker Compose jobs

- [Add Compose Watch to a Docker Compose Project](https://getrush.ai/run/add-compose-watch/docker-compose/)
- [Add Scheduled Database Backups to a Docker Compose Stack](https://getrush.ai/run/add-database-backups/docker-compose/)
- [Add Dependabot to a Docker Compose Repository](https://getrush.ai/run/add-dependabot/docker-compose/)

## More jobs like this: Hand off a long task

- [Add Response Compression to an Axum API](https://getrush.ai/run/add-compression/axum/)
- [Add Response Compression to an Echo App](https://getrush.ai/run/add-compression/echo/)
- [Add Response Compression to a Fastify App](https://getrush.ai/run/add-compression/fastify/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
