I have the following compose.yaml
:
services:
pg-local:
image: postgres:14.7
volumes:
- pgdata:/var/lib/postgresql/data
env_file:
- .env.local_postgres_docker_env
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 30s
timeout: 5s
retries: 3
configuration-manager:
build:
context: ..
ports:
- "5000:8080"
volumes:
- ~/.aws:/root/.aws
depends_on:
db-replicator:
condition: service_started
env_file:
- .env.config_manager_docker_env
db-migrator:
build:
context: ..
volumes:
- .:/migrations
depends_on:
pg-local:
condition: service_healthy
env_file:
- .env.config_manager_docker_env
command: bash -c 'poetry run flask db upgrade && echo "Migration completed successfully"'
db-replicator:
build:
context: ./postgres
depends_on:
db-migrator:
condition: service_completed_successfully
env_file:
- .env.local_postgres_docker_env
- .env.production_postgres_secrets
command: >
bash -c '
PGPASSWORD=${PROD_POSTGRES_PASSWORD} pg_dump -v --host=${PROD_HOST} --username=${PROD_USER} --dbname=${PROD_DB_NAME} --clean --create --no-password --file=/tmp/dump.sql &&
PGPASSWORD=${POSTGRES_PASSWORD} psql --host=pg-local --username=${POSTGRES_USER} < /tmp/globals.sql' &&
PGPASSWORD=${POSTGRES_PASSWORD} psql --host=pg-local --username=${POSTGRES_USER} < /tmp/dump.sql'
volumes:
pgdata:
pg-local
and db-migrator
services are working great!
However the db-replicator
service fails when doing pg_dump
with the following error:
pg_dump: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
All the environment variables are well-defined for all services (checked with `docker compose config)
- I tried to use another network
- I tried
network_mode: host
- I tried running the relevant image with
docker run ...
(and notdocker compose
) and it worked.