Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending docker official postgres image

I'm trying to extend the official docker postgres image in order to install a custom python module so I can use it from withing a plpython3 stored procedure.

Here's my dockerfile

FROM postgres:9.5
RUN apt-get update && apt-get install -y postgresql-plpython3-9.5 python3
ADD ./repsug/ /opt/smtnel/repsug/
WORKDIR /opt/smtnel/repsug/
RUN ["python3", "setup.py", "install"]
WORKDIR /

My question is: do I need to add ENTRYPOINT and CMD commands to my Dockerfile? Or are they "inherited" FROM the base image?

The example in the official readme.md shows a Dockerfile which only changes the locale, without ENTRYPOINT or CMD.

I also read in the readme that I can extend the image by executing custom sh and/or sql scripts. Should I use this feature instead of creating my custom image? The question in this case is how I make sure the scripts are run only once at "install time" and not every time? I mean, if the database is already created and populated, I would not want to overwrite it.

Thanks, Awer

like image 628
Awer Muller Avatar asked Feb 10 '16 15:02

Awer Muller


1 Answers

If you define a new ENTRYPOINT in your Dockerfile it will override the inherited ENTRYPOINT. So in that case, Postgres will not be able to be initialized automatically (unless yo write the same ENTRYPOINT).

https://docs.docker.com/engine/reference/builder/#entrypoint

Also, the official postgres image let you add .sql/.sh files in the /docker-entrypoint-initdb.d folder, so they can be executed once the database is initialized.

Finally, if you don't want that Postgres remove your data, you can mount a volume between the /var/lib/postgresql/data folder and a local folder in each docker run ... command to persist them.

like image 76
JesusTinoco Avatar answered Nov 18 '22 20:11

JesusTinoco