3

I am using the posgres:10.0 image to run PostgreSQL inside a container. My docker-compose.yml looks fairly simple:

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

For my project, we will start using the Multicorn extension, see http://multicorn.org/. To make/make install this, I need to do:

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

Then afterwards, I can add a multicorn.sql script and add it to the /docker-entrypoint-initdb.d/ directory, which will be called when the Docker container is starting up:

CREATE EXTENSION multicorn;

But how can I make/make install Multicorn within the Docker container? Ideally, I want to keep using the posgres:10.0 and not invent/create my own version, as I don't want to inherit the maintenance hassle.

1 Answers1

0

You should create an own Dockerfile - this is the sense of Dockerfiles ;) Otherwise you would have to do some hacking with scripts at startup or something like this. Don't do that...

Another quick note: If you want to build it from source, you might want to have a look at this and use a multi-stage docker build: https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds

Jonas Heinisch
  • 363
  • 2
  • 12
  • About multi-stage builds: would it work to create a temporary container with postgresql installed, make/make install the extension in that temporary container and then copy the extension from `/usr/lib/postgresql/x.y/lib/...` to the same directory of the target/final container? –  Nov 06 '17 at 15:58