0

I have a docker image that needs some credentials passed from the host-environment. How do I pass Linux environmental variables into dockerfile. No flags attachment only dockerfile.

When I build the Docker Image it fetches packages from a local repo that needs authentication. This is all automated and the credentials depend on the host machine that is running.

I have tried to google it and only found how to pass hard-coded varibles. But I need e.g.

export VAR=[PASSWORD]

to be passed into the dockerfile.

ENV PASSWORD = $VAR
Aard
  • 39
  • 1
  • 6
  • If you need the variables at build time, you should look at the `ARG` statement rather than the `ENV` statement. – Hans Kilian Feb 08 '23 at 13:45
  • Remember that anything in a Dockerfile can be trivially extracted later by anyone who gets the image. Even using `ARG` as @HansKilian suggests will compromise whatever credentials you pass in. [What is the best way to pass AWS credentials to a Docker container?](/questions/36354423/what-is-the-best-way-to-pass-aws-credentials-to-a-docker-container) discusses passing one particular type of secret at runtime; [Clone private git repo with dockerfile](/questions/23391839/clone-private-git-repo-with-dockerfile) is a more specific case of actually needing a secret during a build. – David Maze Feb 08 '23 at 14:24

1 Answers1

0

You should use ARG with the ENV in your Dockerfile:

ARG name
ENV env_name $name

When you build your image, pass the arg from your local environment

docker build -t my_image --build-arg name=$MY_LOCAL_ENV_VAR .
buddemat
  • 4,552
  • 14
  • 29
  • 49