I am trying to pass a variable to a simple docker script
I tried the method described here.
FROM golang:latest
ARG buildtime_variable=default_value
ENV env_var_name=$buildtime_variable
RUN echo $env_var_name
I tried building it with
docker build --build-arg buildtime_variable=a_value .
And I get the results
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM golang:latest ---> da66b002dd02
Step 2/4 : ARG buildtime_variable=default_value ---> Running in 91055d467539 Removing intermediate container 91055d467539 ---> 1241ad5c9f12
Step 3/4 : ENV env_var_name=$buildtime_variable ---> Running in c61292041ccf Removing intermediate container c61292041ccf ---> 4eeac4402f5b
Step 4/4 : RUN echo $env_var_name ---> Running in 80ba16d2ee9c Removing intermediate container 80ba16d2ee9c ---> b814420cc448 Successfully built b814420cc448
I was expecting it to echo a_value, instead it does no such thing, its like the variable didn't get correctly transmitted.
I tried it with RUN echo A
which produced the expected result of echoing A
Is it time to use an env-file? or do I not need to resort to that?
EDIT
Just did an update, my version info is
docker version Client: Docker Engine - Community Version:
18.09.2 API version: 1.39 Go version: go1.10.8 Git commit: 6247962 Built: Sun Feb 10 04:12:31 2019 OS/Arch: windows/amd64 Experimental: falseServer: Docker Engine - Community Engine: Version: 18.09.2 API version: 1.39 (minimum version 1.24) Go version:
go1.10.6 Git commit: 6247962 Built: Sun Feb 10 04:28:48 2019 OS/Arch: windows/amd64 Experimental:
false
EDIT
I just tried switching to Linux containers and trying an example from here
FROM ubuntu
ARG CONT_IMG_VER
ENV CONT_IMG_VER v1.0.0
RUN echo $CONT_IMG_VER
docker build --build-arg CONT_IMG_VER=v2.0.1 .
This actually prints out a value!
unfortunately this is the default value v1.0.0 instead of the variable defined by --build-arg
Also, I need this to work with a windows container.