Skip to content

[BUG] $POSTGRES_PORT env var not working with migrations via docker compose. #1186

@veloper

Description

@veloper

Describe the bug
It looks like the port config setting for postgresql is working and implemented properly in the docker-compose.prop.yml file but when I got to run it I get the following output.

╰─± docker-compose -f ./docker-compose.prod.yml --env-file ./.env up
[+] Running 5/5
 ✔ Network sim_default         Created                                                                                                                  0.1s 
 ✔ Container sim-db-1          Created                                                                                                                  0.1s 
 ✔ Container sim-migrations-1  Created                                                                                                                  0.8s 
 ✔ Container sim-realtime-1    Created                                                                                                                  0.4s 
 ✔ Container sim-simstudio-1   Created                                                                                                                  0.5s 
Attaching to db-1, migrations-1, realtime-1, simstudio-1
db-1          | The files belonging to this database system will be owned by user "postgres".
db-1          | This user must also own the server process.
db-1          | 
db-1          | The database cluster will be initialized with locale "en_US.utf8".
db-1          | The default database encoding has accordingly been set to "UTF8".
db-1          | The default text search configuration will be set to "english".
db-1          | 
db-1          | Data page checksums are disabled.
db-1          | 
db-1          | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db-1          | creating subdirectories ... ok
db-1          | selecting dynamic shared memory implementation ... posix
db-1          | selecting default "max_connections" ... 100
db-1          | selecting default "shared_buffers" ... 128MB
db-1          | selecting default time zone ... Etc/UTC
db-1          | creating configuration files ... ok
db-1          | running bootstrap script ... ok
db-1          | performing post-bootstrap initialization ... ok
db-1          | initdb: warning: enabling "trust" authentication for local connections
db-1          | initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
db-1          | syncing data to disk ... ok
db-1          | 
db-1          | 
db-1          | Success. You can now start the database server using:
db-1          | 
db-1          |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db-1          | 
db-1          | waiting for server to start....2025-08-29 16:26:21.733 UTC [46] LOG:  starting PostgreSQL 17.6 (Debian 17.6-1.pgdg12+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
db-1          | 2025-08-29 16:26:21.738 UTC [46] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1          | 2025-08-29 16:26:21.783 UTC [49] LOG:  database system was shut down at 2025-08-29 16:26:20 UTC
db-1          | 2025-08-29 16:26:21.833 UTC [46] LOG:  database system is ready to accept connections
db-1          |  done
db-1          | server started
db-1          | CREATE DATABASE
db-1          | 
db-1          | 
db-1          | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db-1          | 
db-1          | 2025-08-29 16:26:22.344 UTC [46] LOG:  received fast shutdown request
db-1          | waiting for server to shut down....2025-08-29 16:26:22.347 UTC [46] LOG:  aborting any active transactions
db-1          | 2025-08-29 16:26:22.362 UTC [46] LOG:  background worker "logical replication launcher" (PID 52) exited with exit code 1
db-1          | 2025-08-29 16:26:22.364 UTC [47] LOG:  shutting down
db-1          | 2025-08-29 16:26:22.367 UTC [47] LOG:  checkpoint starting: shutdown immediate
db-1          | 2025-08-29 16:26:22.478 UTC [47] LOG:  checkpoint complete: wrote 921 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.049 s, sync=0.057 s, total=0.114 s; sync files=301, longest=0.014 s, average=0.001 s; distance=4238 kB, estimate=4238 kB; lsn=0/1908980, redo lsn=0/1908980
db-1          | 2025-08-29 16:26:22.495 UTC [46] LOG:  database system is shut down
db-1          |  done
db-1          | server stopped
db-1          | 
db-1          | PostgreSQL init process complete; ready for start up.
db-1          | 
db-1          | 2025-08-29 16:26:22.615 UTC [1] LOG:  starting PostgreSQL 17.6 (Debian 17.6-1.pgdg12+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
db-1          | 2025-08-29 16:26:22.630 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db-1          | 2025-08-29 16:26:22.630 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db-1          | 2025-08-29 16:26:22.650 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db-1          | 2025-08-29 16:26:22.660 UTC [62] LOG:  database system was shut down at 2025-08-29 16:26:22 UTC
db-1          | 2025-08-29 16:26:22.673 UTC [1] LOG:  database system is ready to accept connections
migrations-1  | $ bunx drizzle-kit migrate
migrations-1  | No config path provided, using default 'drizzle.config.ts'
migrations-1  | Reading config file '/app/apps/sim/drizzle.config.ts'
migrations-1  | Using 'postgres' driver for database querying
migrations-1  | 36 |   async queryWithCache(queryString, params, query) {
migrations-1  | 37 |     if (this.cache === void 0 || is(this.cache, NoopCache) || this.queryMetadata === void 0) {
migrations-1  | 38 |       try {
migrations-1  | 39 |         return await query();
migrations-1  | 40 |       } catch (e) {
migrations-1  | 41 |         throw new DrizzleQueryError(queryString, params, e);
migrations-1  |                    ^
migrations-1  | error: Failed query: CREATE SCHEMA IF NOT EXISTS "drizzle"
migrations-1  | params: 
migrations-1  |   query: "CREATE SCHEMA IF NOT EXISTS \"drizzle\"",
migrations-1  |  params: [],
migrations-1  | 
migrations-1  |       at queryWithCache (/app/node_modules/drizzle-orm/pg-core/session.js:41:15)
migrations-1  | 
migrations-1  | error: connect ECONNREFUSED 172.25.0.2:5433
migrations-1  |    errno: -111,
migrations-1  |  syscall: "connect",
migrations-1  |     port: 5433,
migrations-1  |  address: "172.25.0.2",
migrations-1  |     code: "ECONNREFUSED"
migrations-1  | 
migrations-1  |       at new ExceptionWithHostPort (internal:shared:42:10)
migrations-1  | 
migrations-1  | error: script "db:migrate" exited with code 1
[⣯] applying migrations...
migrations-1 exited with code 1
realtime-1    | 2025-08-29T16:26:37.955Z WARN [Better Auth]: Social provider github is missing clientId or clientSecret
realtime-1    | 2025-08-29T16:26:37.957Z WARN [Better Auth]: Social provider google is missing clientId or clientSecret

To Reproduce
Steps to reproduce the behavior:

  1. Clone the repo
  2. cd path/to/repo
  3. cp ./app/.env.example ./.env
  4. sed -i '' 's/^# POSTGRES_PORT=5432$/POSTGRES_PORT=5433/' ./.env
  5. docker-compose -f ./docker-compose.prod.yml --env-file ./.env up

Expected behavior
Normal Startup

Additional context

  • I ensured that I ran docker-compose -f ./docker-compose.prod.yml --env-file ./.env down first to ensure there was no cross-attempt contamination.
  • I tried a re-run from that partial state -- no go.
  • I tried doing it all over again with the auth keys generated and in place -- no go.
  • I tried changing the default DATABASE_URL to the following -- all no-go.
    • postgresql://postgres:password@localhost:5433/postgres
    • postgresql://postgres@localhost:5433/postgres
    • postgresql://postgres@localhost:5433/simstudio
    • postgresql://postgres@db:5433/simstudio

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions