Docker environment file variable substitution

Hi,

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

  1. Download artifact containing file
  2. Run variable substitution
  3. Pass file when starting container

Does this make sense? If it does, where do I find documentation to achieve above.

Thanks for a great product

Hi @joakim.carselind,

Thanks for reaching out.

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,
Jeremy

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.

Regards

Hi @joakim.carselind,

You’re very welcome!

Sounds good, I’ll wait to hear back then.

Thanks,
Jeremy

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?

Thanks

Hi @joakim.carselind,

You beat me to it! I’m glad to hear you got it worked out, thanks for letting me know and posting the solution for others following along.

Please reach out if you need any other help. I hope you have a great rest of the week.

Thanks,
Jeremy

Thanks @jeremy.miller! I’ll try to write up a blog post and then I can share it here. Perhaps even guest post on the Octopus blog :wink:

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.