How can I access Docker set Environment Variables From a Cron Job

后端 未结 8 1664
野性不改
野性不改 2021-01-30 20:24

I\'ve recently tried running a cron job from within a linked docker container and run into an issue. My main docker container is linked to a postgres container and its port numb

8条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 20:31

    The environment is set, but not available to the cron job. To fix that, you can do these two simple things

    1) Save the env to a file in your ENTRYPOINT or CMD

    CMD env > /tmp/.MyApp.env && /bin/MyApp
    

    2) Then read that env into your cron command like this:

    0 5 * * * . /tmp/.MyApp.env; /bin/MyApp
    

提交回复
热议问题