ppostnov
ppostnov

Reputation: 149

Docker file set arguments from environment variables

I want to just print HOMEPATH variable from my machine:

This is my Dockerfile:

FROM python:3.8-slim

ARG some_path=$HOMEPATH
RUN echo "this is some_path: $some_path"

but receiving empty string, during image creation - docker build -t test_image . :

enter image description here

What I am doing wrong ?

Upvotes: 0

Views: 665

Answers (1)

BMitch
BMitch

Reputation: 264236

Docker doesn't expose the builder to this sort of security risk. The build environment could have sensitive data in environment variables that they do not want exposed when the build arbitrary docker images. To inject a variables during build, you must explicitly pass it on the build command line with:

docker build --build-arg "some_path=$HOMEPATH" -t test_image . 

Note that the path on the build server is typically not something you would want to inject in a build. The same build should work regardless of where you perform the build.

Upvotes: 1

Related Questions