我需要为在Docker内部运行的Postgres实例创建扩展-特别是 postgis 。我没有关注其他SO帖子,包括this one,都无济于事。
这是我到目前为止所拥有的...
Dockerfile
FROM postgres
COPY ext-script.sql /docker-entrypoint-initdb.d
ext-script.sql
create extension pgcrypto;
create extension postgis;
Docker 运行命令
docker run -d -p 5432:54323 -e POSTGRES_PASSWORD=somepassword -e POSTGRES_USER=someuser -v postgres-data:/var/lib/postgresql/data --name dbcontainer dbimage
日志
docker logs dbcontainer
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/ext-script.sql
CREATE EXTENSION
2020-02-20 22:18:01.090 UTC [60] ERROR: could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory
2020-02-20 22:18:01.090 UTC [60] STATEMENT: create extension postgis;
psql:/docker-entrypoint-initdb.d/ext-script.sql:2: ERROR: could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory
我想念什么?
更新
我最终使用了postgis dockerhub image。
当您知道如何时,一切都会变得容易:)
# Dockerfile
FROM postgis/postgis
COPY data.sql /docker-entrypoint-initdb.d
答案 0 :(得分:2)
PostGIS与pgcrypto不同,它不包含在默认的PostgreSQL软件包中,需要在调用create extension postgis;
之前从某些源安装它。