# Migrate a Docker Compose app from Coolify to Gregale

> Move one Docker Compose service from Coolify, check PostgreSQL and volume compatibility, and verify the app before changing DNS.

Start with one stateless service. Reuse its Dockerfile, deploy it on a
temporary Gregale hostname and verify it before you touch production DNS.
You can keep your existing PostgreSQL database if the new service can reach
it securely. A Coolify named volume, host mount or private service address
does not move with the app.

## Decide what moves

| In Coolify | For the first Gregale deploy |
| --- | --- |
| API built from a Dockerfile | Reuse its build context and Dockerfile. Expose the container's listening port; listen on `0.0.0.0:$PORT`. |
| Generated values and secrets | Recreate the values the API actually needs. Replace Coolify-generated hostnames, URLs and credentials instead of copying the entire environment. |
| `db:5432` on the Coolify network | Keep the database only if you already have a secure, usable route from Gregale. Otherwise leave it on Coolify while you test against a restored copy. |
| Postgres data in a volume | Take an application-database backup and verify a restore. The Coolify instance backup is not a backup of your app's database. |
| Docker volume or host-mounted uploads | For file uploads, [copy the volume to a private S3 bucket](https://gregale.dev/docs/migrate-docker-volume-uploads-to-s3.md) or keep the workload on Coolify until you can change how it stores files. Gregale does not mount those paths. |
| Custom domain and workers | Leave DNS, the old API and job consumers alone for the candidate test. Move them separately once you know which service owns writes and jobs. |

Use Coolify's **source Compose** and check the **deployable Compose** for
hostnames and settings it injected. The deployable one is useful for an
inventory, not a file to copy blindly. See
[Coolify's Compose docs](https://coolify.io/docs/services/configuration/docker-compose)
and [Gregale's container compatibility](https://gregale.dev/docs/container-compatibility.md).

## Deploy the API without moving the stack

[Download the runnable Compose example](https://gregale.dev/examples/coolify-compose-migration.zip).
It includes the same Python Dockerfile in both variants:
`compose.coolify.yaml` models an API and a volume-backed Postgres service,
while `compose.yaml` keeps only the API. It is a disposable fixture, not a
backup utility or a production-ready write API.

From the unpacked directory, keep the full source configuration as a
reference. Plan the API-only file and deploy only if the plan shows the
one expected workload and no new database:

```sh
gregale deploy --project --project-slug coolify-move --prefix coolify-test- --dry-run
gregale deploy --project --project-slug coolify-move --prefix coolify-test-
```

Use a new project slug and prefix if those names already exist. Read
warnings before you apply. A local missing-`DATABASE_URL` warning does not
tell you whether a secret has already been configured on the app. And a
healthy route does not prove database access. Gregale can answer
`/healthz` at the edge; the marker endpoints check the app and Postgres.

In our dry run with both source services, Gregale listed `db` as a managed
dependency, not a container it would start. It warned that it would not
honor the API's `depends_on: service_healthy` for that datastore. The
API-only plan listed one HTTP workload and no new database.

## Keep the database or rehearse the move

- **Keep it for now:** A private name like `db` is not a database address on
  Gregale. Use a TLS-verified endpoint, a scoped database role, and
  connection and firewall rules you can keep in place. Gregale's default
  external ports are 80 and 443; reaching an external Postgres listener on
  5432 requires the additional port on Pro or Scale. Don't make a private
  Coolify database broadly public just to finish the migration. See
  [Networking](https://gregale.dev/docs/networking.md).
- **Move it separately:** For a Docker-volume-backed Postgres service, take
  a logical dump of the **application database** and test its restore to a
  separate database. Check extensions, ownership, permissions and row
  counts. Then bind the new database as `DATABASE_URL` (see
  [Managed PostgreSQL](https://gregale.dev/docs/postgres.md)). A Compose plan that provisions
  managed Postgres starts with an empty database; it never imports the
  old volume. [Coolify's database backup docs](https://coolify.io/docs/databases/backups)
  explain how to export your application data.

## Prove the candidate can read and write

Keep the demo behind bearer access. Create a disposable managed database
named `coolify-demo-db`, then attach two credentials to the app from the
example. If you chose a different prefix, use the app name in your plan.

```sh
gregale postgres attach coolify-demo-db coolify-test-api --env DATABASE_URL --access read_write
gregale postgres attach coolify-demo-db coolify-test-api --env MIGRATION_DATABASE_URL --access migration
gregale deploy --path api --name coolify-test-api
```

The redeploy picks up the bindings. Only the release task receives
`MIGRATION_DATABASE_URL`; it uses `api/seed.sql` to set up the disposable
marker table. The running app uses the narrower runtime credential.

At the temporary URL, read `/markers/seed-before-move`, POST to
`/markers/written-on-gregale` and read that marker back. Both reads should
return HTTP 200 with `"present":true`. Use synthetic rows only. For a real
app, run the check against a sandbox or a dedicated test record and account.

**Verified on Gregale.** We deployed the API-only Compose plan, attached a
disposable managed PostgreSQL database, then deployed the same API with the
marker seed as a release task. On the bearer-protected hostname, it read
`seed-before-move`, wrote `written-on-gregale`, and read the new marker back.
The sample also passed the marker round trip against local PostgreSQL. We did
not connect to a real Coolify server, import a production database, or move
a domain.

## Move the domain last

1. Keep the Coolify deployment available. Check the new URL for routing,
   health, reads and writes. Compare logs and suspend duplicate workers
   or scheduled jobs before letting the new copy consume real work.
2. Follow [Custom domains](https://gregale.dev/docs/custom-domains.md) to verify ownership, switch routing
   and confirm HTTPS. Verify the production hostname after the change,
   not just the temporary URL. DNS caches mean a switch or reversal is
   not instantaneous.
3. If both app versions share one database, make sure both work with its
   schema until the old traffic drains. If the database moved, use a
   write freeze or a controlled replication cutover; do not accept writes
   in two independent databases. Changing DNS back is not a database
   rollback. Decide where new writes will go before you cut over.

Comparing options first? See [Gregale vs Coolify](https://gregale.dev/vs/coolify) or
[Coolify alternatives](https://gregale.dev/articles/coolify-alternatives).

Source: https://gregale.dev/docs/migrate-from-coolify
