I'm trying to set up a postgres db in docker container updated by liquibase, but run into strange errors.
Here is the docker compose:
version: '3.8'
services:
db:
image: postgres:15-alpine
container_name: transactions-db
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: transactions
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
liquibase:
container_name: liquibase-container
image: liquibase/liquibase
command: update
environment:
LIQUIBASE_COMMAND_CHANGELOG_FILE: /liquibase/db.changelog/migrations.yml
LIQUIBASE_COMMAND_DRIVER: org.postgresql.Driver
LIQUIBASE_COMMAND_URL: jdbc:postgresql://host.docker.internal:5432/transactions
LIQUIBASE_COMMAND_USERNAME: root
LIQUIBASE_COMMAND_PASSWORD: root
LIQUIBASE_COMMAND_DEFAULT_SCHEMA_NAME: public
LIQUIBASE_SEARCH_PATH: /liquibase
volumes:
- ./src/main/resources/db.changelog:/liquibase/db.changelog
volumes:
postgres-data:
And here is the error:
ERROR: Exception Details
liquibase-container | ERROR: Exception Primary Class: ChangeLogParseException
liquibase-container | ERROR: Exception Primary Reason: /liquibase/db.changelog/migrations.yml does not exist
liquibase-container | ERROR: Exception Primary Source: 4.32.0
liquibase-container |
liquibase-container | Unexpected error running Liquibase: /liquibase/db.changelog/migrations.yml does not exist
I do have migrations.yml
as well as some SQL files it refers to present in src/main/resources/db.changelog
thats why I'm mounting the volume
I also tried mounting a single file migrations.yml
ending same error
According to the Liquibase documentation for Docker the volume in the Liquibase image for mounting your local changelog directory is /liquibase/changelog
and not /liquibase/db.changelog
but when I tried setting that I still got the same error.
After looking through DEBUG logs I noticed it is expecting LIQUIBASE_COMMAND_CHANGELOG_FILE
to be a relative path to the changelog file from the /liquibase
directory on the container.
When I set LIQUIBASE_COMMAND_CHANGELOG_FILE: changelog/migrations.yml
the update executed as expected. My working config is below
services:
db:
image: postgres:15-alpine
container_name: transactions-db
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: transactions
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
liquibase:
container_name: liquibase-container
image: liquibase/liquibase
command: update
environment:
LIQUIBASE_COMMAND_CHANGELOG_FILE: changelog/migrations.yml
LIQUIBASE_COMMAND_DRIVER: org.postgresql.Driver
LIQUIBASE_COMMAND_URL: jdbc:postgresql://host.docker.internal:5432/transactions
LIQUIBASE_COMMAND_USERNAME: root
LIQUIBASE_COMMAND_PASSWORD: root
LIQUIBASE_COMMAND_DEFAULT_SCHEMA_NAME: public
LIQUIBASE_LOG_LEVEL: DEBUG
volumes:
- ./src/main/resources/db.changelog/:/liquibase/changelog/
volumes:
postgres-data: