Is there anyway to have a DockerBuild file use an environment variables file?

I have a Docker container that will have a LARGE (about 100) number of customization settings. I would prefer to have more flexibility than coding the defaults all into the DockerFile. I notice that the docker run command supports this option:

--env-file value              Read in a file of environment variables (default [])

Is there any way to have a similar file-driven mechanism used by docker build? Or is there a better way entirely?

  • How to use env attribute of Vagrant Docker provider?
  • How to run cucumber/selenium tests in Docker?
  • Docker-Compose: Initialize vs Run
  • Why use Consul with Kubernetes, Docker, Mesos?
  • Docker SIGTERM not being delivered to node.js/coffee app when started with flags
  • docker-compose with nginx is not working
  • How to capture the output of multiple commands run in docker separately?
  • php significant slower on docker then kvm
  • How to completely destroy docker container from marathon UI?
  • symbol not found errors with glibc
  • Error pulling image (latest) from centos, Authentication is required
  • One docker container per node or many containers per big node
  • 2 Solutions collect form web for “Is there anyway to have a DockerBuild file use an environment variables file?”

    Environment files are not supported for builds.

    This has been discussed at large and very likely won’t be added.
    Introducing env in the build command creates host dependent builds.

    The ARG command and --build-args are available during builds but do not support a file like you require.

    As user2105103 suggests, you can COPY the env file in your build steps and then source it during a RUN.

    COPY .env /.env
    RUN set -uex; \
        . /.env; \
        echo $MY_ENV_VAR
    

    You can write a bash script that would dynamically build your custom Dockerfiles .

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.