This script will read your secret file and set each line as an env variable in your container.
I' assuming that you already has a entrypoint file in your Dockerfile. So now, you need to copy and paste the contents of set_env_secrets.sh to your entrypoint(you don't need the first line).
Now, you need to create a secret, the name could be whatever you like. I'm using the name of my application as a pattern for my secrets name. For this example, my secret name will be super-project and the content will be.
DB_HOST=mariadb
DB_DATABASE=mydatabase
DB_USERNAME=superuser
DB_PASSWORD=supersecretpassword
Then, in my compose file, I need to set that secret name. Like this:
application:
image: IMAGENAME
secrets:
- super-project
labels:
- io.rancher.container.pull_image=always
environment:
**SECRET_NAME:super-project**
Now you just need to deploy your app and each line of that secret file will be a env variable for your application.
Thanks for the code!
Improvements i made:
https://gist.github.com/marlluslustosa/0240f89e2d8ffa14c23ca77fcbda39a3