Docker Community Forums

Share and learn in the Docker community.

How to set default env for all containers that will be started

Is there any way to set default computing env for all future container?

Use case:
I have build infrastructure and want to set machine-specific env for all containers that will be started on machine.

While you can’t directly set ENV variable values when running docker build, you can use ARG to pass through --build-arg values right into your ENV instructions.

First, you’ll need to define an additional ARG variable, which is only there to pass through the value to your environment variable:

ARG buildtime_variable=default_value # <- this one’s new
ENV env_var_name=$buildtime_variable # we reference it directly
Almost done! Now, when you’re building your image you can override the default_value of “buildtime_variable” any time you like:

$ docker build --build-arg buildtime_variable=a_value # … the rest of the build command is omitted

Try an environment variable file
–env-file /path/to/envfiles.
Use the -e , --env , and --env-file flags to set simple (non-array) environment variables in the container you’re running, or overwrite variables that are defined in the Dockerfile of the image you’re running.

Don’t knew about build-arg trick. Thanks.

But, unfortunately, I don’t have possibilities to rebuild all images. Also, they can be external.

And I really want to do such things on the docker engine layer. And don’t want to any affect on the run/start container usage for users.