I'm setting up a docker container which requires a cronjob to do a backup using awscli
.
I'm having a problem with the cron job being able to access the environment variables of the docker container. As I work around on startup I print all environment variables to a file printenv > /env
.
When I try to use source
from the cron job (I have tried both directly in crontab and in a script called by crontab) it doesn't seem to work.
I made a simplified version of my project to demonstrate the issue (including rsyslog
for logging):
Dockerfile:
FROM debian:jessie
# Install aws and cron
RUN apt-get -yqq update
RUN apt-get install -yqq awscli cron rsyslog
# Create cron job
ADD crontab /etc/cron.d/hello-cron
RUN chmod 0644 /etc/cron.d/hello-cron
# Output environment variables to file
# Then start cron and watch log
CMD printenv > /env && cron && service rsyslog start && tail -F /var/log/*
crontab:
# Every 3 minutes try to source /env and run `aws s3 ls`.
*/3 * * * * root /usr/bin/env bash & source /env & aws s3 ls >> /test 2>&1
When I start the container I can see /env
was created with my variables but it never gets sourced.
source
? I'm pretty sure it should just besource
and not/source
env
and not using the actualenv
command?/env
that has the environment variables that need to be sourced. Is that wrong Philip?