2016-12-06 141 views
0

我正在编写一个Dockerfile,它引入外部转储,然后加载它 - https://github.com/scala-eveapi/postgres-sde/commit/95d2ed70dff8326c9acc75c56c9a7b8c8f6bbc73 - docker build正常工作。运行时,它恢复了数据库,但在运行.sql后,它只是退出,而不是保持postgres服务器的活着。从postgres docker容器继承 - 不保持守护进程活着?

文件:

FROM postgres:latest 
ADD https://www.fuzzwork.co.uk/dump/latest/postgres-20161114-TRANQUILITY.dmp.bz2 sde.bz2 
# ADD postgres-20161114-TRANQUILITY.dmp.bz2 sde.bz2 
RUN bunzip2 sde.bz2 
COPY load-sde.sh /docker-entrypoint-initdb.d/01-load-sde.sh 
COPY add-constraints.sql /docker-entrypoint-initdb.d/02-add-constraints.sql 

其他两个文件是:

#!/bin/bash 
set -e 

pg_restore -d "${POSTGRES_DB:-$POSTGRES_USER}" -U "$POSTGRES_USER" sde 

和SQL:

alter table "mapSolarSystems" 
alter column "solarSystemName" set not null; 

alter table "invTypes" 
alter column "typeName" set not null; 

alter table "staStations" 
alter column "stationName" set not null; 

alter table "staStations" 
alter column "solarSystemID" set not null; 

日志:

The files belonging to this database system will be owned by user "postgres". 
This user must also own the server process. 

The database cluster will be initialized with locale "en_US.utf8". 
The default database encoding has accordingly been set to "UTF8". 
The default text search configuration will be set to "english". 

Data page checksums are disabled. 

fixing permissions on existing directory /var/lib/postgresql/data ... ok 
creating subdirectories ... ok 
selecting default max_connections ... 100 
selecting default shared_buffers ... 128MB 
selecting dynamic shared memory implementation ... posix 
creating configuration files ... ok 
running bootstrap script ... ok 
performing post-bootstrap initialization ... ok 
syncing data to disk ... 
WARNING: enabling "trust" authentication for local connections 
You can change this by editing pg_hba.conf or using the option -A, or 
--auth-local and --auth-host, the next time you run initdb. 
ok 

Success. You can now start the database server using: 

    pg_ctl -D /var/lib/postgresql/data -l logfile start 

**************************************************** 
WARNING: No password has been set for the database. 
     This will allow anyone with access to the 
     Postgres port to access your database. In 
     Docker's default configuration, this is 
     effectively any other container on the same 
     system. 

     Use "-e POSTGRES_PASSWORD=password" to set 
     it in "docker run". 
**************************************************** 
waiting for server to start....LOG: database system was shut down at 2016-12-06 12:05:18 UTC 
LOG: MultiXact member wraparound protections are now enabled 
LOG: database system is ready to accept connections 
LOG: autovacuum launcher started 
done 
server started 
ALTER ROLE 


/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/01-load-sde.sh 
ERROR: role "yaml" does not exist 
STATEMENT: ALTER TABLE "agtAgentTypes" OWNER TO yaml; 

[...] pg_restore errors 

WARNING: errors ignored on restore: 89 
+1

您的Dockerfile中没有CMD或ENTRYPOINT,所以容器停止,这是正常的 – user2915097

+0

您可以发布容器中的日志吗? – Yuva

+0

发布日志。 – Reactormonk

回答

0

看最后三行初始Dockerfile(你继承了一句:https://github.com/docker-library/postgres/blob/edd455e5b1dbfddc280beb244228054374f2f3dd/9.6/Dockerfile):

ENTRYPOINT ["/docker-entrypoint.sh"] 

EXPOSE 5432 
CMD ["postgres"] 

你延伸的Dockerfile,但你没有设置运行命令..所以,容器停下来,它会被标记为退出。

+0

补充说,重建后,通过'docker run '运行,仍然在运行pg恢复后退出。 – Reactormonk

+0

查看“码头日志”和“码头事件” – user2915097

+0

@Reactormonk你添加了/ docker-entrypoint.sh文件吗?你需要从这里添加它:https://github.com/docker-library/postgres/blob/edd455e5b1dbfddc280beb244228054374f2f3dd/9.6/docker-entrypoint.sh到你的项目,否则'ENTRYPOINT [“/docker-entrypoint.sh”] '不会工作 –

0

错误导致它明显停止。我添加了yaml角色,现在它可以正常工作。