DB migration not working in docker
🐛 Bug Report
Describe the bug Fresh docker instance is not creating a db
kan | 2026-02-17T23:45:28.432Z ERROR [Better Auth]: relation "user" does not exist
kan | # SERVER_ERROR: [error: relation "user" does not exist] {
kan | length: 104,
kan | severity: 'ERROR',
kan | code: '42P01',
kan | detail: undefined,
kan | hint: undefined,
kan | position: '107',
kan | internalPosition: undefined,
kan | internalQuery: undefined,
kan | where: undefined,
kan | schema: undefined,
kan | dataType: undefined,
kan | constraint: undefined,
kan | file: 'parse_relation.c',
kan | line: '1449',
kan | routine: 'parserOpenTable'
kan | }
To Reproduce Steps to reproduce the behavior:
services:
kan:
image: ghcr.io/kanbn/kan:latest
restart: unless-stopped
container_name: kan
ports:
- "3002:3000"
env_file:
- /etc/docker-secrets/kan.env
- /etc/docker-secrets/aws-vger-ops.env
networks:
- postgres-network
- redis-network
- kan-network
networks:
postgres-network:
external: true
redis-network:
external: true
kan-network:
external: true
Using :
- postgres:16
kan-# \c kan
You are now connected to database "kan" as user "pgadmin".
kan-# \dn
List of schemas
Name | Owner
--------+-------------------
public | pg_database_owner
(1 row)
kan-# \dt
Did not find any relations.
docker compose up go to register, fails
env
# Required
NEXT_PUBLIC_BASE_URL=https://kan.home.arpa
BETTER_AUTH_SECRET=----
POSTGRES_URL="postgresql://kan:-----@postgres:5432/kan"
# Optional: disable sign-up after initial setup
NEXT_PUBLIC_DISABLE_SIGN_UP=false
# Optional: Redis for rate limiting (uses in-memory if omitted)
REDIS_URL=redis://redis:6379
NEXT_PUBLIC_AVATAR_BUCKET_NAME=----
NEXT_PUBLIC_ATTACHMENTS_BUCKET_NAME=-----
NEXT_PUBLIC_STORAGE_URL= ----
NEXT_PUBLIC_ALLOW_CREDENTIALS=true
NEXT_PUBLIC_DISABLE_EMAIL=true
S3_REGION=----
S3_ENDPOINT=----
S3_ACCESS_KEY_ID=----
S3_SECRET_ACCESS_KEY=----
S3_FORCE_PATH_STYLE=false
Expected behavior Ability to register and sign in
Docker doesn't appear to do a db migration A migration instance doesn't appear to be public
You have create and run a kan-migrate instance
cd /tmp
git clone https://github.com/kanbn/kan.git
docker build --target migrate -t kan-migrate-local -f apps/web/Dockerfile .
docker run --rm \
--network postgres-network \
-e POSTGRES_URL="postgresql://user:password@postgres:5432/db" \
kan-migrate-local
or a docker profile in the compose to run the migration
services:
kan-migrate:
image: kan-migrate-local
profiles:
- migrate
environment:
- POSTGRES_URL
networks:
- postgres-network
kan:
image: ghcr.io/kanbn/kan:latest
restart: unless-stopped
....
Then
POSTGRES_URL="postgresql://kan:password@postgres:5432/kan" \
docker compose --profile migrate up kan-migrate
That gets you up and running
Another bug: You should be able to run it with the env of DB but for some reason the env parsing was wonky and picking up NEXT_PUBLIC_BASE_URL for the postgres url
❯ sh-4.4# docker run --rm \
> --network postgres-network \
> --env-file docker-secrets/kan.env \
> kan-migrate-local
No config path provided, using default 'drizzle.config.ts'
Reading config file '/db/drizzle.config.ts'
Using 'pg' driver for database querying
[⣷] applying migrations...DrizzleQueryError: Failed query: CREATE SCHEMA IF NOT EXISTS "drizzle"
params:
at NodePgPreparedQuery.queryWithCache (file:///db/node_modules/drizzle-orm/pg-core/session.js:41:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async PgDialect.migrate (file:///db/node_modules/drizzle-orm/pg-core/dialect.js:54:5)
at async migrate (file:///db/node_modules/drizzle-orm/node-postgres/migrator.js:4:3) {
query: 'CREATE SCHEMA IF NOT EXISTS "drizzle"',
params: [],
cause: Error: getaddrinfo ENOTFOUND base
at /db/node_modules/pg-pool/index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///db/node_modules/drizzle-orm/node-postgres/session.js:113:20
at async NodePgPreparedQuery.queryWithCache (file:///db/node_modules/drizzle-orm/pg-core/session.js:39:16)
at async PgDialect.migrate (file:///db/node_modules/drizzle-orm/pg-core/dialect.js:54:5)
at async migrate (file:///db/node_modules/drizzle-orm/node-postgres/migrator.js:4:3) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'base'
}
}
npm notice
npm notice New major version of npm available! 10.8.2 -> 11.10.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.10.0
npm notice To update run: npm install -g [email protected]
npm notice
Thanks for flagging @pjaol - I've updated the self hosting docs to include the new migrate service configuration
You should be able to run it with the env of DB but for some reason the env parsing was wonky and picking up NEXT_PUBLIC_BASE_URL for the postgres url
I've not been able to replicate this one yet. Please could you share more details about your setup so I can try to replicate?
You should be able to run it with the env of DB but for some reason the env parsing was wonky and picking upNEXT_PUBLIC_BASE_URL for the postgres url
I've not been able to replicate this one yet. Please could you share more details about your setup so I can try to replicate?
This might be ok, I haven't tried again but I did have an '@' in my postgres password which broke url parsing and I was using env files.
For those that don't want to copy the sources and use the hosted GitHub Container Registry's image, here is the compose.yml service for migrating the database.
services:
kan-migrate:
image: ghcr.io/kanbn/kan-migrate:latest
environment:
POSTGRES_URL: $POSTGRES_URL # Replace with your own Postgres URL
networks:
- kan-network
Thanks for flagging @pjaol - I've updated the self hosting docs to include the new migrate service configuration
The doc change is still not released, on https://docs.kan.bn/guides/self-hosting/introduction the migration service is not mentioned.
Also, it would be really nice if changed deployment suggestions can be advertised in the changelog. Otherwise people only find this after something breaks after an update, which is a bit too late.
As of June 17th, the doc change is still not released.
For those that don't want to copy the sources and use the hosted GitHub Container Registry's image, here is the
compose.ymlservice for migrating the database.services: kan-migrate: image: ghcr.io/kanbn/kan-migrate:latest environment: POSTGRES_URL: $POSTGRES_URL # Replace with your own Postgres URL networks: - kan-network
This solution does work but you need to manually run the migration container at first. Because it exits with code 0 before doing any work.