如何在官方 Postgres 容器中启动 Cron / Crond
How to Start Cron / Crond inside the Official Postgres Container
在official postgres
alpine image中默认[=10=]不是运行ning。我如何定义 Dockerfile
以确保守护进程 运行 在后台运行?我希望默认情况下它是 运行ning,如果可能的话,即使容器重新启动也是如此。
我试图将 CMD ["/usr/sbin/crond"]
添加到我的 Dockerfile
但我没有成功。任何想法如何 运行 结合 postgres
?
更新
我已经添加了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.
pg_cron
必须添加到 shared_preload_libraries
。根据文档:
# add to postgresql.conf:
shared_preload_libraries = 'pg_cron'
然后您必须重新启动 PostgreSQL。
在official postgres
alpine image中默认[=10=]不是运行ning。我如何定义 Dockerfile
以确保守护进程 运行 在后台运行?我希望默认情况下它是 运行ning,如果可能的话,即使容器重新启动也是如此。
我试图将 CMD ["/usr/sbin/crond"]
添加到我的 Dockerfile
但我没有成功。任何想法如何 运行 结合 postgres
?
更新
我已经添加了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.
pg_cron
必须添加到 shared_preload_libraries
。根据文档:
# add to postgresql.conf:
shared_preload_libraries = 'pg_cron'
然后您必须重新启动 PostgreSQL。