我无法在Docker启动时使用架构演进管理器初始化数据库。我的docker文件如下
FROM postgres:10-alpine
WORKDIR /opt/ext-api-db
COPY . .
RUN apk add py-pip ruby ruby-rdoc
RUN gem install schema-evolution-manager && \
pip install awscli
RUN cp docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d
EXPOSE 5432
docker-entrypoint-initdb.d包含一个初始化脚本
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE ${POSTGRES_USER}_test;
GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_USER}_test TO $POSTGRES_USER;
EOSQL
# Applying Sem Scripts
echo
echo 'PostgreSQL initialzing Data...'
echo
"pg_ctl -o" -c listen_addresses='localhost'" -D "$PGDATA" -w restart"
sem-apply --url postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost/$POSTGRES_DB
sem-apply --url postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost/$POSTGRES_DB_test
在Docker容器启动时,数据库创建良好,但是架构演化管理器表示其无法连接到数据库 这是完整的堆栈跟踪
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sh
CREATE DATABASE
GRANT
PostgreSQL initialzing Data...
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Address not available
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
/usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/library.rb:136:in `rescue in system_or_error': Error running command[psql --no-align --tuples-only --no-psqlrc --command "select count(*) from pg_namespace where nspname='schema_evolution_manager'" postgresql://user:pass@localhost/db]: Non zero exit code[pid 47 exit 2] running command[psql --no-align --tuples-only --no-psqlrc --command "select count(*) from pg_namespace where nspname='schema_evolution_manager'" postgresql://user:pass@localhost/db] (RuntimeError)
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/library.rb:129:in `system_or_error'
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/db.rb:32:in `psql_command'
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/db.rb:90:in `schema_schema_evolution_manager_exists?'
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/scripts.rb:86:in `scripts_previously_run'
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/scripts.rb:48:in `each_pending'
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/lib/schema-evolution-manager/db.rb:22:in `bootstrap!'
from /usr/lib/ruby/gems/2.5.0/gems/schema-evolution-manager-0.9.39/bin/sem-apply:30:in `<top (required)>'
from /usr/bin/sem-apply:23:in `load'
from /usr/bin/sem-apply:23:in `<main>'
这是我的docker-compose配置
version: "3"
services:
ext-api-db:
build:
context: .
container_name: ext-api-db
env_file: docker-compose.env
hostname: ext-api-db
networks:
- ext
ports:
- "15432:5432"
restart: unless-stopped
volumes:
- .:/opt/ext-api-db:delegated
networks:
ext:
external:
name: ext
有人可以告诉我如何解决此问题吗?
答案 0 :(得分:0)
您的入口点脚本应为:
// echo char to stdout