Docker构建ARG始终为空字符串 [英] Docker build ARG always empty string
本文介绍了Docker构建ARG始终为空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里有一个dockerfile:
I have a dockerfile here:
FROM golang:1.13-alpine as build
ARG DIR=somevalue
RUN echo $DIR
输出为
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换为另一个名称示例DIR1时,DIR始终为空.Docker版本在这里
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.
推荐答案
可以通过传递-no-cache
选项尝试运行,对我来说它按预期运行
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
这篇关于Docker构建ARG始终为空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文