用dump生成一个postgres开发环境
我使用docker-compose
来创build我的整个生产环境。
我的Dockerfile
是:
FROM postgres:9.5 ADD container/sql /sql ADD container/init-db.sh /docker-entrypoint-initdb.d/
脚本init-db.sh
是:
#!/bin/bash set -e psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL CREATE USER user WITH ENCRYPTED PASSWORD '1234'; CREATE DATABASE my_db; GRANT ALL PRIVILEGES ON DATABASE my_db TO user; CREATE ROLE user_role; GRANT user_role to my_db; EOSQL cat /sql/*.sql | psql -v ON_ERROR_STOP=1 --username user
我可以将这个Dockerfile
指向我docker-compose.yml
,一切正常!
但…
当我尝试使用claycephas/flyway
图像来迁移我的数据库时,我的init-db.sh
机器不会等待init-db.sh
完成。
有我如何configuration这两个图像:
version: '2' services: db_pg: build: ./scripts/docker/db_pg/ container_name: db_pg ports: - "5432:5432" expose: - "5432" db_pg_migration: image: claycephas/flyway container_name: db_pg_migration command: -url=jdbc:postgresql://db_pg/my_db -user=user -password=1234 -locations=filesystem:/dbscripts migrate volumes: - ./scripts/database/migration/:/dbscripts depends_on: - db_pg links: - "db_pg"
这是错误:
db_pg_migration | Flyway 4.0.3 by Boxfuse db_pg_migration | db_pg_migration | ERROR: Unable to obtain Jdbc connection from DataSource (jdbc:postgresql://db_pg/my_db) for user 'user': Connection to db_pg:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
如何configurationdb_pg_migration
以等待数据库完全初始化?