加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

RUN命令中的ARG替换不适用于Dockerfile

发布时间:2020-12-16 03:29:37 所属栏目:安全 来源:网络整理
导读:在我的Dockerfile中,我有以下内容: ARG a-versionRUN wget -q -O /tmp/alle.tar.gz http://someserver/server/$a-version/a-server-$a-version.tar.gz mkdir /opt/apps/$a-version 但是在构建时: --build-arg http_proxy=http://myproxy","--build-arg a

在我的Dockerfile中,我有以下内容:

ARG a-version
RUN wget -q -O /tmp/alle.tar.gz http://someserver/server/$a-version/a-server-$a-version.tar.gz && 
    mkdir /opt/apps/$a-version

但是在构建时:

--build-arg http_proxy=http://myproxy","--build-arg a-version=a","--build-arg b-version=b"

步骤10/15:RUN wget …在路径中显示$a-version而不是替换值,构建失败.

我按照here所示的说明操作,但必须遗漏其他内容.

My questions is,what could be causing this issue and how can i solve
it?

最佳答案
不要在变量名中使用 – .

Docker构建将始终显示Dockerfile中记录的行,尽管变量值.

所以使用这个变量名a_version:

ARG a_version

看这个例子:

Dockerfile:

FROM alpine

ARG a_version
RUN echo $a_version

建立:

$docker build . --build-arg a_version=1234
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM alpine
 ---> a41a7446062d
Step 2/3 : ARG a_version
 ---> Running in c55e98cab494
 ---> 53dedab7de75
Removing intermediate container c55e98cab494
Step 3/3 : RUN echo $a_version                <<< note this <<
 ---> Running in 56b8aeddf77b
1234                                          <<<< and this <<
 ---> 89badadc1ccf
Removing intermediate container 56b8aeddf77b
Successfully built 89badadc1ccf

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读