17

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.

2
  • 1
    Output from what? Please include your build command. Commented Apr 5, 2020 at 17:08
  • Did you work this out? I have the same problem. Commented Jan 14, 2021 at 6:04

2 Answers 2

29

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Me too. I found the explanation here. The relevant part of the documentation is here.
@NadavZingerman you're the real MVP :)
0

Can you try running by passing the --no-cache option, it is working as expected for me

❯❯❯ docker build . --no-cache
Sending build context to Docker daemon  194.7MB
Step 1/3 : FROM golang:1.13-alpine as build
 ---> 2e384b27f926
Step 2/3 : ARG DIR=somevalue
 ---> Running in c53bbb64dda1
Removing intermediate container c53bbb64dda1
 ---> b76b21aca433
Step 3/3 : RUN echo $DIR
 ---> Running in 6c49d289e258
somevalue
Removing intermediate container 6c49d289e258
 ---> d51e5579f1cb
Successfully built d51e5579f1cb

However, if it has built the same image once, it will not output anything as it has the layer cached:

❯❯❯ docker build .
Sending build context to Docker daemon  194.7MB
Step 1/3 : FROM golang:1.13-alpine as build
 ---> 2e384b27f926
Step 2/3 : ARG DIR=somevalue
 ---> Using cache
 ---> b76b21aca433
Step 3/3 : RUN echo $DIR
 ---> Using cache
 ---> d51e5579f1cb
Successfully built d51e5579f1cb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.