Postgres / Postgis Dockerfile容器无法绑定IPv6套接字错误

我熟悉Docker并试图创build一个Postgres和各种扩展用于开发的容器。 这个想法是其他开发人员可以在本地机器上设置容器并开始开发。

为此我创build了下面的Dockerfile,它build立在Postgis docker镜像之上,并安装了一些额外的扩展。

FROM mdillon/postgis:9.6 RUN apt-get update RUN apt-get -y install python3 postgresql-plpython3-9.6 RUN apt-get clean && \ rm -rf /var/cache/apt/* /var/lib/apt/lists/* EXPOSE 5432:5432 

然后我用命令运行Dockerfile定义,并得到以下输出到我的terminal:

 docker run --name dockerthing -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 dockerthing 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 ... ok 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. Success. You can now start the database server using: pg_ctl -D /var/lib/postgresql/data -l logfile start waiting for server to start....LOG: could not bind IPv6 socket: Cannot assign requested address HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. LOG: database system was shut down at 2017-09-24 09:29:51 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 /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/postgis.sh CREATE DATABASE UPDATE 1 Loading PostGIS extensions into template_postgis CREATE EXTENSION CREATE EXTENSION CREATE EXTENSION CREATE EXTENSION Loading PostGIS extensions into postgres CREATE EXTENSION CREATE EXTENSION CREATE EXTENSION CREATE EXTENSION waiting for server to shut down....LOG: received fast shutdown request LOG: aborting any active transactions LOG: autovacuum launcher shutting down LOG: shutting down LOG: database system is shut down done server stopped PostgreSQL init process complete; ready for start up. LOG: database system was shut down at 2017-09-24 09:29:59 UTC LOG: MultiXact member wraparound protections are now enabled LOG: database system is ready to accept connections LOG: autovacuum launcher started LOG: using stale statistics instead of current ones because stats collector is not responding 

initdb-postgis.sh脚本可以在这里find: https : //github.com/love/docker-postgis/blob/master/9.6-2.3/initdb-postgis.sh

看日志,我很困惑发生了什么事情。 为什么数据库在两者之间closures以及为什么端口绑定失败? 如果我直接运行docker-postgis映像,则不会发生这种情况。 只有当我在FROM语句中使用它。

无论如何,最后的问题是,我不能从我的主机连接到数据库,像psql -h localhost -p 5432 -d postgres -U postgres

那么,我的Dockerfile有什么问题吗?或者是我从根本上误解了有关do​​ckerfiles或从主机连接到它们的问题?