Answer the question
In order to leave comments, you need to log in
How to get environment variables in docker cron?
Building cron container:
Dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get -y install cron
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
# Apply cron job
RUN crontab /etc/cron.d/hello-cron
CMD ["cron", "-f"]
* * * * * echo "TEST ${TEST}" > /proc/1/fd/1 2>/proc/1/fd/2
$ docker build . -t cron
$ docker run --env TEST=xxx cron env | grep TEST
TEST=xxx
$ docker run --env TEST=xxx cron
TEST
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question