I am building out my product environments using Docker and want to make sure my secrets and keys are secure. To do so, I would like to use .env files. For convenience sake, I would like to avoid dealing with Docker secrets.
For local development I am using OpenFaas which requires the image be pushed to Docker Hub for use with k3s OpenFaas. I am concerned that the Docker Hub image may contain the variables from the .env file used with docker-compose.yaml.
Are the environment variables included in the Docker Hub image repository?
The docs and This stack overflow response suggest that environment variables are only used at "runtime", which I understand to mean they are not included. That should mean only someone with admin access to the server would be able to inspect the image for the secrets. Am I wrong in this assumption? Should I be using Docker secrets?
Update 08/19/21
Through testing I feel more confident that the .env variables are not included in the image on Docker Hub. Note I am using OpenFaas faas-cli
to handle docker deployment. To test this I did the following:
- Comment out the
environment_file:
section of the .yml file - Upload the image using
faas-cli up <functions>.yml
(this part builds and pushes the docker image to a Docker Hub repository, then deploys the OpenFaas function) - Invoke the function. The function simply returns the environment variable. With the environment variables "commented out" of the .yml file, the function returns "undefined" meaning the variable is not available to the function.
This gave me some confidence, but not as much as I'd like, so next I did the following:
- Uncomment the
environment_file:
section of the .yml file - Run the command
faas-cli up -f <functions>.yml --no-cache --skip-push
. - Invoke the function
--no-cache ensures that the image is pulled fresh, --skip-push skips the part where the docker image is pushed to the Docker Hub repository. Thus the "build" of the image should use the image created with the "environment_file" commented out, but now "run" with the environment_file uncommented on the local .yml file.
After invoking the function this time, the variable is available and returns appropriately. As long as my interpretation of how the build
, push
, and deploy
portions of the faas-cli
works is correct, then I feel confident the .env file and variables are not part of the Docker Hub image.