Yannic Hamann
Yannic Hamann

Reputation: 5225

How to Start Cron / Crond inside the Official Postgres Container

The crond is not running by default in the official postgres alpine image. How could I define my Dockerfile to make sure that the daemon runs in the background? I want that it is running by default, if possible even when the container gets restarted.

I tried to add CMD ["/usr/sbin/crond"] to my Dockerfile but I didn't succeed. Any thoughts how to run this in combination with postgres?

Update

I have added the answer of tianon:

[...] If you must run crond inside a container, I'd recommend instead using a separate container which runs nothing but crond (and thus Docker can both track its lifecycle, and restart it when/if it fails, the machine restarts, etc). You should be able to connect to the PostgreSQL instance from a second container, but if absolutely necessary, one could use things like --network container:some-postgres in order to join the network namespace of the database container directly.

Upvotes: 1

Views: 948

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324841

pg_cron must be added to shared_preload_libraries. Per the docs:

 # add to postgresql.conf:
 shared_preload_libraries = 'pg_cron'

and you must then restart PostgreSQL.

Upvotes: 1

Related Questions