# Move Compose Passwords into Docker Secrets

Yes. An agent finds every plain-text password in your Compose files, moves each into a Docker secret the image reads from a file, starts every stack, and opens a PR.

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

## What the agent does

The agent starts by listing where passwords live, because the fix is different for an image that can read a secret file and one that cannot. In a repository like docker/awesome-compose, eight samples already do it right: `react-express-mysql/compose.yaml` and `nginx-golang-postgres/compose.yaml` declare a top-level `secrets:` block with `db-password` from `db/password.txt`, mount it on the database service, and set `MYSQL_ROOT_PASSWORD_FILE` or `POSTGRES_PASSWORD_FILE` to `/run/secrets/db-password`. Eleven others still put the value in the environment: `wordpress-mysql` sets `MYSQL_ROOT_PASSWORD=somewordpress` and `WORDPRESS_DB_PASSWORD=wordpress`, `gitea-postgres` sets `POSTGRES_PASSWORD=gitea` and `DB_PASSWD=gitea`, `nextcloud-postgres` repeats `POSTGRES_PASSWORD=nextcloud` on both services, `nextcloud-redis-mariadb` sets `MYSQL_ROOT_PASSWORD` and `MYSQL_PASSWORD`, `prometheus-grafana` sets `GF_SECURITY_ADMIN_PASSWORD=grafana`, `react-rust-postgres` sets `POSTGRES_PASSWORD=mysecretpassword` on `db` and `PG_PASSWORD=mysecretpassword` on `backend`, `aspnet-mssql` sets `SA_PASSWORD: example_123` and repeats it inside its `healthcheck` command, and `wasmedge-kafka-mysql` has `whalehello` both in `MYSQL_ROOT_PASSWORD` and inside a `DATABASE_URL`. `postgresql-pgadmin` reads `${POSTGRES_PW}` and `${PGADMIN_PW}` from a `.env` file, which keeps the value out of the YAML but still hands it to the container as an environment variable any `docker inspect` prints.

Then it reads what each image supports, since a secret is only useful if the process reads the file. The official `postgres`, `mysql` and `mariadb` images accept a `_FILE` suffix on their password variables; `wordpress` accepts `WORDPRESS_DB_PASSWORD_FILE`; `nextcloud` accepts the `_FILE` form of its `POSTGRES_*` and `MYSQL_*` variables; `grafana` reads `GF_SECURITY_ADMIN_PASSWORD__FILE`; `gitea` reads any setting with a `__FILE` suffix through its environment-to-ini step; `pgadmin4` reads `PGADMIN_DEFAULT_PASSWORD_FILE`. The Rust backend in `react-rust-postgres/backend/src/postgres.rs` reads `PG_PASSWORD` with `std::env::var` and nothing else, so it needs a few lines that read a `PG_PASSWORD_FILE` path first. The SQL Server image and the `DATABASE_URL` in the WasmEdge sample take the password only inline, and those two are reported with the reason rather than forced.

For each sample it can fix, the agent follows the layout the repository already uses: a `db/password.txt` holding the value the sample used before, so nothing changes for a reader who just runs `docker compose up`, a top-level `secrets:` entry pointing at that file, `secrets:` on every service that needs it, and the `_FILE` variable in place of the plain one, with the mount path `/run/secrets/<name>`. Where two services shared one password, they share one secret. In `react-rust-postgres` it adds the `PG_PASSWORD_FILE` read to `postgres.rs`, falling back to `PG_PASSWORD` so the backend still runs outside Compose. Each sample's `README.md` gets a line on where the password lives and how to change it.

Every changed stack is brought up in the sandbox: `docker compose config` renders the merged file and catches a secret referenced but not declared, then `docker compose up -d --wait` builds and starts it, and for each stack the agent makes one request that proves the password was read, a `docker compose exec db mysql -uroot -p$(cat db/password.txt)` or `pg_isready`, a WordPress or Nextcloud front page that finishes installing, a Grafana login with the admin password from the file, a Gitea page that reaches its database, a request to the Rust backend on port 8000. It confirms `docker inspect` on each service shows the `_FILE` path and not the value, and runs `docker compose down -v` before the next stack. A stack that does not come up with the secret is reverted and listed with the command output.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Move every plain-text password in this repository's Compose files into Docker secrets and open a pull request. First list every compose.yaml or compose.yml and Dockerfile that contains a password, as an environment value, inside a connection URL, or inside a healthcheck command, and note which samples already use a secrets block. For each image, find out whether it reads the password from a file (a _FILE or __FILE variable, or app code you can change) before touching it. Where it does, add a db/password.txt with the value the sample used, a top-level secrets entry, secrets on each service that needs it, and the file variable in place of the plain one; where the application code is in the repository and reads only an environment variable, add a file read with the environment variable as fallback. Where the image cannot read a file, leave the sample unchanged and say why. Keep the existing secrets-based samples as the pattern. For each changed stack run docker compose config, docker compose up -d --wait, one request or query that proves the password was read, docker inspect to show the value is no longer in the environment, and docker compose down -v. Update each changed README. Open one pull request with a table of one line per sample: the variable moved, the file, the command that proved it, or the reason it was left.",
  "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 one pull request that changes the Compose file and `README.md` in each sample it could convert, adds a `db/password.txt` to each, and in `react-rust-postgres` changes `backend/src/postgres.rs` by a few lines. The description is a table with one row per sample: the variable that moved, the secret file, the command that proved the stack read it, or the reason it stayed, which for `aspnet-mssql` and `wasmedge-kafka-mysql` is that the image or the connection URL takes the password only inline.

The run's record keeps `docker compose config`, each `up -d --wait`, the proving request or query, the `docker inspect` output showing a `_FILE` path where a value used to be, and each `down -v`, in order per stack. The repository has only a CodeQL workflow, so that record is the check a reviewer reads.

Before merging, a reviewer decides whether the sample values should stay in `db/password.txt` as they are, since the file is committed for a sample that must run with one command, and whether the two samples left unchanged deserve a follow-up that changes their images. In their own repositories, that file is gitignored and written by the deploy.

## Run it on every Compose file added

Once the samples use secrets, a GitHub trigger on `pull_request.opened` with a prompt that asks to check any `compose.yaml` the pull request adds or changes for a plain-text password, and to convert it the same way, keeps new stacks on the pattern before they merge. The automation adds the pull request to the prompt; each pull request gets its own run and its own review.

For a company with many repositories, send one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`; each run reads its own Compose files and images, and a `webhook_url` on the key reports `run.completed` with the `session_url` for each.

## Why run it on Rush?

The only way to know an image honours a `_FILE` variable is to start it with one and log in. Doing that for eleven stacks means pulling eleven sets of images, waiting for WordPress and Nextcloud to install themselves, and tearing volumes down between each, which is an afternoon of a laptop's Docker and disk. A Rush sandbox has its own Docker daemon and starts clean, so the agent can bring every stack up from nothing, prove the password was read, and keep every command with its output in the run's record beside the pull request.

The result is a pull request whose table says, per sample, what moved and how it was proven, with the two samples that cannot be converted named rather than silently skipped. The same request works on any repository with Compose files, each in its own sandbox.

## Frequently asked questions

### Is a committed db/password.txt any better than a value in the YAML?

For a sample that must run with one command, the file is the same value in a different place, and the pull request says so. What changes is the mechanism: the container reads the file from `/run/secrets`, the value is no longer in `docker inspect` or `docker compose config` output, and in a real deployment the file is gitignored and written by whatever provisions the host.

### Which images cannot read a secret file?

In this repository, the SQL Server image in `aspnet-mssql`, which takes `SA_PASSWORD` only inline and repeats it in a healthcheck, and the WasmEdge ETL whose password sits inside a `DATABASE_URL`. Both are listed in the pull request with the reason, and left as they were.

### What about the sample that uses a .env file?

`postgresql-pgadmin` reads `${POSTGRES_PW}` and `${PGADMIN_PW}` from `.env`, which keeps the value out of git but still puts it in the container's environment. Both images read `_FILE` variables, so it is converted like the others.

### Does the agent change application code?

Only where the code is in the repository and reads nothing but an environment variable: the Rust backend's `postgres.rs` gains a `PG_PASSWORD_FILE` read with `PG_PASSWORD` as fallback, and its stack is rebuilt and started to prove it.

## More Docker Compose jobs

- [Move Hard-Coded Values in a Compose File into a .env File](https://getrush.ai/run/add-env-file/docker-compose/)
- [Add Hadolint to CI for a Docker Compose Repository](https://getrush.ai/run/add-hadolint-to-ci/docker-compose/)
- [Add Health Checks to a Docker Compose Setup](https://getrush.ai/run/add-health-checks/docker-compose/)

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

- [Add a Dockerfile to an AdonisJS App](https://getrush.ai/run/add-dockerfile/adonisjs/)
- [Add a Dockerfile to an aiohttp App](https://getrush.ai/run/add-dockerfile/aiohttp/)
- [Add a Dockerfile to a Blazor Web App](https://getrush.ai/run/add-dockerfile/blazor/)

## 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/)
