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?
If you are using docker-compose (which now comes bundled with Docker), . env is the default filename for the file that contains variables that are made available to the parser for the docker-compose. yml file ONLY, and not to the build process or container environment variables.
ENV is mainly meant to provide default values for your future environment variables. Running dockerized applications can access environment variables. It's a great way to pass configuration values to your project. ARG values are not available after the image is built.
You can also set build environment variables with --build-arg
. Example on documentation
As you can see, it is an equivalent to docker run --env
, there isn't one for --env-file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With