Search code examples
ruby-on-railsactiverecorddocker-composedockerfile

How to build Docker with env file


I'm stuck with env file during docker build.

I'm trying to build docker image for my ruby project which uses environment variables for a number of reasons. One of the reason is checking either database is available or not(Using ActiveRecord::Base.connection), and based on that going to create/update a database with some master data.

I can use env file during docker run via docker run --env-file='.env' command.

But I want to use those ENV variables during my docker build.

Can anyone help me out with this situations?


Solution

  • You can add ENV myvariable myvalue in your Dockerfile. Check the docker doc.