Docker – 如何在Docker容器中制作/安装扩展?

我正在使用posgres:10.0映像在容器中运行PostgreSQL。 我docker-compose.yml看起来相当简单:

 version: "2" services: db: image: "postgres:10.0" environment: - POSTGRES_USER=postgres - POSTGRES_DB=postgres volumes: - ./volumes/postgresql/postgresql.sh:/docker-entrypoint-initdb.d/postgresql.sh ports: - 5432:5432 

postgresql.sh

 #!/bin/bash echo wal_level=logical >> $PGDATA/postgresql.auto.conf echo max_replication_slots=1 >> $PGDATA/postgresql.auto.conf echo host replication all all trust >> $PGDATA/pg_hba.conf 

对于我的项目,我们将开始使用Multicorn扩展,请参阅http://multicorn.org/ 。 为了使/安装这个,我需要做的:

 git clone git://github.com/Kozea/Multicorn.git cd Multicorn make && make install 

然后,我可以添加一个multicorn.sql脚本,并将其添加到/docker-entrypoint-initdb.d/目录,这将在Docker容器启动时调用:

 CREATE EXTENSION multicorn; 

但是我怎样才能在Docker容器中安装Multicorn? 理想情况下,我想继续使用posgres:10.0而不发明/创build自己的版本,因为我不想inheritance维护的麻烦。

您应该创build一个自己的Dockerfile – 这是Dockerfiles的意义;)否则,你将不得不在启动时使用脚本进行一些黑客攻击或类似的东西。 不要那样做…

另一个快速注意:如果你想从源代码构build它,你可能想看看这个,并使用多阶段docker构build: https : //docs.docker.com/engine/userguide/eng-image/multistage -build /#使用多段-构build