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

后端 未结 8 1663
野性不改
野性不改 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条回答
  •  不思量自难忘°
    2021-01-30 20:39

    To escape any weird characters that could break your script, and according to reasoning from Mark's answer, add this line to your entrypoint.sh:

    env | sed -r "s/'/\\\'/gm" | sed -r "s/^([^=]+=)(.*)\$/\1'\2'/gm" \ > /etc/environment
    

    This way, if you have any variable like affinity:container==My container's friend, it will be converted to affinity:container='=My container\'s friend, and so on.

提交回复
热议问题