docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.2k stars 1.14k forks source link

Please allow user to specify list of extensions to install with `pgxn` #1175

Closed lukehutch closed 10 months ago

lukehutch commented 10 months ago

I'm trying to figure out how to take the basic postgres Docker image, and install a couple of extensions into that image, after the volume has been created. I don't see an easy way to do this in compose.yaml, and if I try to run apt-get or similar in /docker-entrypoint-initdb.d/init.sh, it fails, because there is no sudo command.

Could you please add a way for the user to specify a list of extensions to install after the image has been created, maybe in an environment variable or something, so that the user can simply list extensions in compose.yaml?

ImreSamu commented 10 months ago

I'm trying to figure out how to take the basic postgres Docker image, and install a couple of extensions into that image,

A best practice is to extend the basic postgres docker image so that new extensions can be included. For example, see the postgis/postgis dockerfiles

lukehutch commented 10 months ago

@ImreSamu Thanks, I tried doing that, but I don't want to maintain or ship my own docker image, I would prefer to be able to use the postgres/postgres docker image from Docker Hub, and simply extend it by specifying which extensions to install from pgxn in my compose.yaml file.

ImreSamu commented 10 months ago

and simply extend it by specifying which extensions to install from pgxn in my compose.yaml file.

I'm not sure about your specific needs, but creating a universal pgxn Docker installation script (using --build_arg) that always works 100% is challenging. This is due to a few reasons based on my experience in trying to build a comprehensive postgres-postgis-geo-bundle image with additional pgxn libraries:

For instance, pgxn pg_bm25 requires an additional Rust development environment.

Also, for production environments, it's important to include all runtime dependencies in the Docker image for security auditing. Therefore, installing these during the runtime initialization phase is not advisable.

Many pgxn packages (like pgtap, h3, etc.) have pre-compiled versions for Debian PostgreSQL, which don't require extra development environments. It's preferable to use these if available.

FROM postgres:16
RUN set -eux \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        postgresql-$PG_MAJOR-pgvector \
        postgresql-$PG_MAJOR-h3 \
        postgresql-$PG_MAJOR-hypopg \
        postgresql-$PG_MAJOR-pgtap \
        ....
lukehutch commented 10 months ago

OK, thanks, that's helpful. I'll go ahead and close this then.