0

I am running a docker container using --env VAR="foo" to set a few variables. When I run commands on this running container from the same shell / environment that I started the container, everything is fine.

The problem is that now I want to run commands against this container from cron. When cron runs the same command, the ENV variables in the container no longer exist.

How can I persist these ENV variables in the container regardless of where it is accessed from?

Edit: To clarify, I docker run from a standard shell. In the cron job, I use docker exec and that is when the ENV vars disappear.

I have also noticed that some host machines I can't do any exec's on docker containers from a cron job.

shiznatix
  • 1,087
  • 1
  • 20
  • 37
  • duplicate of http://stackoverflow.com/questions/26822067/running-cron-python-jobs-within-docker ? you can use the trick of Alban Mouton, among other solutions – user2915097 Oct 11 '15 at 22:10
  • @user2915097 not quite, I am running a docker command from the host machine cron - not trying to run cron from within a docker container itself – shiznatix Oct 13 '15 at 19:35

1 Answers1

0

I presume you use docker run inside your cron task.

If that's the case that's normal. You are starting a new container from the same image.

If you want to use the same container (with all your env variables set), you can use docker exec.

https://docs.docker.com/reference/commandline/exec/

Aurélien Bottazini
  • 3,249
  • 17
  • 26
  • I updated my question - I am using it in the way you suggest from the beginning but thats how the issue exists – shiznatix Oct 13 '15 at 16:44