All jobs

Add a Production Override to a Docker Compose Project

Yes. An agent adds a compose.prod.yaml that drops bind mounts and debug ports, builds the production stages, waits on database health, proves it and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads how the development stack is wired before it writes an override. In a project shaped like the react-express-mysql sample of docker/awesome-compose, compose.yaml builds backend from backend/ with target: development and args: NODE_ENV=development, runs npm run start-watch, publishes 80, 9229 and 9230, bind-mounts ./backend/src read-only plus package.json and package-lock.json into /code, hides node_modules behind a back-notused volume, and reads the database password from the db-password secret at db/password.txt. db is mariadb:10.6.4-focal on the private network with a db-data volume and MYSQL_ROOT_PASSWORD_FILE pointing at the same secret. frontend builds with target: development, publishes 3000, bind-mounts ./frontend/src and sits on public only, with depends_on: backend and no health condition anywhere.

The Dockerfiles already contain the production shapes. backend/Dockerfile starts from node:lts AS development, declares ARG NODE_ENV=production, exposes $PORT 9229 9230, runs npm ci, sets a HEALTHCHECK that runs node healthcheck.js every 30 seconds, and ends with CMD ["node", "src/index.js"]; backend/package.json keeps nodemon, mocha and cross-env in devDependencies, which npm ci omits once NODE_ENV is production, so start-watch cannot run in that image and the command has to change. frontend/Dockerfile chains development, a builder stage that runs npm run build, a dev-envs stage, and a final nginx:1.13-alpine stage that copies /code/build into /usr/share/nginx/html. frontend/src/setupProxy.js forwards /api to http://backend with the prefix stripped during development, and App.js fetches /api/, so a production nginx needs the same rule or the page shows nothing.

The agent writes compose.prod.yaml as an override, applied with docker compose -f compose.yaml -f compose.prod.yaml. For backend it sets build.args to NODE_ENV=production, replaces the command with node src/index.js, resets volumes with !reset so no source is mounted, and overrides ports with !override to leave only what the proxy needs, with restart: unless-stopped. For frontend it drops the development target so the last stage, the nginx image, is built, adds frontend/nginx.conf with a location /api/ block that proxies to backend and strips the prefix as setupProxy.js does, and adds the one COPY of that file to the nginx stage in frontend/Dockerfile. For db it adds a healthcheck that runs mysqladmin ping with the password file, so depends_on can use condition: service_healthy the way nginx-golang-postgres/compose.yaml already does with pg_isready. backend/src/config.js reads DATABASE_PASSWORD as a file path, so the secret wiring stays as it is.

It then runs docker compose -f compose.yaml -f compose.prod.yaml config and reads the merged output to confirm the mounts and debug ports are gone, runs up --build -d, waits for docker compose ps to show backend healthy through the Dockerfile's HEALTHCHECK, requests /healthz on the backend and / and /api/ through nginx, then down -v. The sample's README.md gets the two commands and a sentence on when to use each file. compose.yaml itself is not edited, so docker compose up for development behaves exactly as before.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "codex",
  "input": "Add a production override file to the react-express-mysql Compose project in this repository and open a pull request. Read react-express-mysql/compose.yaml, backend/Dockerfile, backend/package.json, backend/src/config.js, backend/src/server.js, backend/healthcheck.js, frontend/Dockerfile, frontend/src/setupProxy.js and README.md first. Write compose.prod.yaml as an override: build the backend with NODE_ENV=production and run node src/index.js with no bind mounts and no inspector ports; build the frontend's final nginx stage and add an nginx config that proxies /api to the backend with the prefix stripped, copied in by the Dockerfile; give the database a healthcheck and make dependents wait on it; add restart policies. Do not change compose.yaml. Verify with docker compose -f compose.yaml -f compose.prod.yaml config and up --build, check /healthz and the proxied /api/ route, then tear down. Document the commands in the README and put the config output and the curl results in the pull request description.",
  "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 that adds react-express-mysql/compose.prod.yaml and frontend/nginx.conf, adds one COPY line to frontend/Dockerfile, and extends the sample's README.md. compose.yaml, the backend Dockerfile and the secret file are unchanged. The description includes the merged docker compose config output so the reviewer sees exactly what the override removed and added.

The run's record keeps the up --build log, the docker compose ps lines showing the health states, and the responses from /healthz and from /api/ through nginx, so the claim that the production stack starts and serves is backed by output rather than by the file alone.

Before merging, a reviewer checks that the nginx location matches what setupProxy.js did in development, that no EXPOSEd inspector port is published by the override, that the mysqladmin health command reads the password from the secret rather than an environment variable, and that the images are pinned as tightly as the team wants before anything leaves a laptop.

Run it on every new Compose project

A script on your server lists repositories through GET /o/{org}/github, looks for a compose.yaml with target: development or source bind mounts and no second Compose file, and sends one POST /o/{org}/sessions with this prompt and the repository in resources for each. Each run reads its own Dockerfiles, so a project whose final stage is nginx gets a proxy config and one that serves from Node gets only the command and mount changes, and each opens its own pull request.

The key's webhook_url receives run.completed or run.failed when each turn ends, with data.session_url for the pull request link and the docker compose output.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A production Compose file is only right once it has been started: a bind mount left in, a stage name that no longer exists, a proxy rule that differs from the dev server's. The sandbox has Docker, so the agent builds both images, starts the three services, waits on the health checks and reads the responses, and the pull request carries that output instead of a request to try it.

The change spans the Compose file, an nginx config, a Dockerfile stage and the README, and it has to leave the development path untouched. One run returns all of it with its log, and the same prompt runs across every Compose project in the org at once, each in its own sandbox reading its own Dockerfiles.

Frequently asked questions

Why a separate file instead of editing compose.yaml?

compose.yaml is the development stack, with hot reload through bind mounts and nodemon. An override applied with a second -f keeps that file as it is and lets docker compose config show the merged result. !reset and !override in the override remove the mounts and ports cleanly rather than leaving empty keys.

Why does the backend command change?

With NODE_ENV=production, npm ci in backend/Dockerfile installs no devDependencies, and nodemon is one of them, so npm run start-watch would fail. The override runs node src/index.js, which is what the Dockerfile's own CMD already does, and src/index.js handles SIGTERM for a clean stop.

How does the frontend reach the API in production?

In development setupProxy.js forwards /api to http://backend and strips the prefix. The nginx stage has no such rule, so the agent adds frontend/nginx.conf with the same location /api/ proxy and copies it into the image. App.js keeps fetching /api/ unchanged.

Does the database wait properly now?

Yes. The override adds a healthcheck to db with mysqladmin ping reading the root password from the secret file, and backend depends on it with condition: service_healthy, so the first query in src/server.js does not race the database's startup.

More Docker Compose jobs

More jobs like this: Hand off a long task

Keep reading