Docker reloads. bash_profile and problems encountered by crond using environment variables

  docker, question

I wrote a Dockerfile that installed the crond service.

Add some environment variables to /root/.bash_profile

# Add some environment variables to /root/.bash_profile
 CMD crond && tail -f /dev/null

Use the following command to create the startup container

docker run -d myimage

Then log in

docker exec -it 7as6f76 /bin/bash

Now there are two questions:

1, using crond to execute expect script cannot find the environment variable I set
2. The environment variable I set cannot be used after logging in using the docker exec command

I tried setting upCMD ["/bin/bash", "/home/sh/"]Instart.shBash_profile.

Not working properly

Regarding question 1, I am/etc/crontabThe problem can be solved in the following ways

30 22 * * * root source /root/.bash_profile;  /bin/expect /home/sh/ >> /home/log/zfgfh.log

For question 2, after getting into the container, manuallysource /root/.bash_profileonce

But I don’t think these two methods are very formal, it should be dockerfile, or start docker, or crond where to set it.
I can solve my problem gracefully.

Thank you first

  • docker run -eSpecify environment variables
  • Passed in DockerfileENVThe instruction specifies the environment variable