How to use secret .env vars without exposing them to repository

7/26/2019

I have a pipenv-environment running in a Dockercontainer and I need some variables from a .env file.

The container is running in a Kubernetes pod.

I can't upload the .env file to the repository because the variables in .env are secret.

My question is if there is a way to get my variables from a secret to the .env file.

I tried creating the .env file in my Dockerfile but ran into the problem that I couldn't figure out how to get the variables accessible in the Dockerfile.

This is what I tried in my Dockerfile:

#create .env file for pipenv
RUN echo DATABASE_URL=$DATABASE_URL > .env 
RUN echo API_EMAIL=$API_EMAIL>> .env
RUN echo API_PASSWORD=$API_PASSWORD>> .env

The three variables get set in a secret and the secret is referenced to the pod. Unfortunately the variables are not accessible.

Does anyone have an idea how I can get the variables from the secret into a .env file in my container? Thanks for any ideas

-- flo3719
docker
dockerfile
google-kubernetes-engine
kubernetes

1 Answer

7/26/2019

move the commands that add entries to .env file from Dockerfile to container startup script before launching the actual container process.

OR

You can create a secret object from key=value pairs and mount it as .env file inside container

-- P Ekambaram
Source: StackOverflow