我正在尝试使用以下Dockerfile在Docker容器中创建一个postgres实例。
FROM postgres
ENV POSTGRES_DB dspace
ENV POSTGRES_USER dspace
ENV POSTGRES_PASSWORD dspace
COPY init.sql /docker-entrypoint-initdb.d/
这是我的init.sql
create extension pgcrpyto
我正在使用Codenvy服务来运行此容器。初始化时,我看到以下错误。
[STDOUT] server started
[STDOUT] Reading package lists...
[STDOUT] Reading package lists...
[STDOUT] Building dependency tree...
[STDOUT] CREATE DATABASE
[STDOUT]
[STDOUT] CREATE ROLE
[STDOUT]
[STDOUT]
[STDOUT] /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
[STDOUT] Reading state information...
[STDOUT] 2018-02-15 19:17:34.931 UTC [399] ERROR: could not open extension control file "/usr/share/postgresql/10/extension/pgcrpyto.control": No such file or directory
[STDOUT] 2018-02-15 19:17:34.931 UTC [399] STATEMENT: create extension pgcrpyto
[STDERR] psql:/docker-entrypoint-initdb.d/init.sql:1: ERROR: could not open extension control file "/usr/share/postgresql/10/extension/pgcrpyto.control": No such file or directory
注意,我的解决方案基于以下帖子。 How to create postgres extension inside the container?
答案 0 :(得分:2)
以下回购邮件解决了我的问题。看来我需要提供一个shell脚本来执行SQL。
https://github.com/DSpace-Labs/DSpace-codenvy
Dockerfile
# From https://github.com/DSpace-Labs/dspace-dev-docker/tree/master/postgres
FROM postgres
ENV POSTGRES_DB dspace
ENV POSTGRES_USER dspace
ENV POSTGRES_PASSWORD dspace
COPY install-pgcrypto.sh /docker-entrypoint-initdb.d/
install-pgcrypto.sh
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
create extension pgcrypto;
EOSQL