Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build ARG always empty string

I have a dockerfile here:

FROM golang:1.13-alpine as build
ARG DIR=somevalue
RUN echo $DIR

Output is

Sending build context to Docker daemon  57.37MB
Step 1/3 : FROM golang:1.13-alpine as build
 ---> 2e384b27f926
Step 2/3 : ARG DIR=somevalue
 ---> Running in 3cd3457a795f
Removing intermediate container 3cd3457a795f
 ---> ecfa2f50c4fa
Step 3/3 : RUN echo $DIR
 ---> Running in aab4e31e0e14

Removing intermediate container aab4e31e0e14
 ---> 5351cb77c245
Successfully built 5351cb77c245

DIR is always empty when I try DIR to another name example DIR1 it is empty too. Docker version is here

 Client:

 Version:           18.09.8
 API version:       1.39
 Go version:        go1.11
 Git commit:        2c0a67b
 Built:             Fri Sep  6 02:50:44 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server:

 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11
  Git commit:       1d8275b
  Built:            Fri Sep  6 02:51:05 2019
  OS/Arch:          linux/amd64
  Experimental:     false

However, when I try to another machine, it is right, it will echo some value. Who can give me some tips to find the problem about the wrong machine? thanks.

like image 721
kevinsir Avatar asked Dec 13 '25 06:12

kevinsir


1 Answers

This is obviously not the problem in your example, but I got this error when declaring an ARG before the FROM. Moving the ARG I needed below FROM resolved the problem.

like image 120
Jim Hunziker Avatar answered Dec 16 '25 10:12

Jim Hunziker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!