Starting Docker containers with specific environment variables is a bit cumbersome in my opinion. I’ve developed a .NET tool to extract configuration from example appsettings.json and produce an .env file ready to be substituted and passed to container using --env-file .env. I’ve looked at this and it touches that the current way of passing environment variables have room for improvement.¨
I’m using AzDo to build and the thought process
At build time create .env and publish as artifact. Docker image is pushed during build as well
Octopus
Download artifact containing file
Run variable substitution
Pass file when starting container
Does this make sense? If it does, where do I find documentation to achieve above.
To achieve this I believe what you would need to do is have a Deploy a Package step, and use the Substitute Variables in Files option within Configure Features.
Specify the .env file for the substitutions, then in a subsequent docker step, you would point it at the env-file on the machine that has had its variables substituted.
Please let me know if that works for you or if we need to dig in further.
Thanks for quick reply! I’ll get back tomorrow when I’m back at work and hopefully have the time to update my build pipeline to produce the configuration nuget artifact.
Update: Using --env-file '#{Octopus.Action[Docker environment file].Output.Package.InstallationDirectoryPath}/.env' worked!
Time taken to resolve this and I have an artifact (nuget) containing the .env file in root and it gets downloaded by the package step and - hopefully - transformed by substituting variables. Next step that starts the Docker container is executed in another folder and hence the file is not found. How do I make the “Run Docker Container” step aware of the previously created file?