从postgres docker容器继承 - 是否让守护进程保持活力?

时间:2016-12-06 11:30:18

标签: docker

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

文件:

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

2 个答案:

答案 0 :(得分:1)

错误导致它显然停止。我添加了yaml角色,现在它可以正常运行。

答案 1 :(得分:0)

查看最初的Dockerfile上的最后三行(您继承的那一行:https://github.com/docker-library/postgres/blob/edd455e5b1dbfddc280beb244228054374f2f3dd/9.6/Dockerfile):

ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 5432
CMD ["postgres"]

你正在扩展Dockerfile,但是你没有设置命令来运行......所以,容器停止并且它将被标记为已退出。