docker build --build-arg 失去值并扩展为空字符串

docker build --build-arg 失去值并扩展为空字符串

使用docker版本1.9.0

我有一个提供 ubuntu 信任镜像 (trusty-mirror) 的 docker 容器。我正在尝试构建第二个容器,并希望它从 trusty-mirror 更新和安装软件包。

我的第二个容器的 Dockerfile 有;

FROM ubuntu:14.04

RUN sed -i -e s#http://archive.ubuntu.com#${MIRROR}#g \
           -e s#http://security.ubuntu.com#${MIRROR}#g \
           /etc/apt/sources.list
RUN cat /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get -y autoremove

我使用以下方式将 MIRROR 信息传递给 docker build--build-arg 选项,就像这样;

ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' trusty-mirror 2>/dev/null)
docker build --build-arg MIRROR=ftp://$ip

当其运行时;

+++ docker inspect --format '{{ .NetworkSettings.IPAddress }}' trusty-mirror
++ ip=172.17.0.2
++ docker build --build-arg MIRROR=ftp://172.17.0.2 .
Sending build context to Docker daemon 8.192 kB
Step 1 : FROM ubuntu:14.04
 ---> e9ae3c220b23
Step 2 : RUN sed -i -e s#http://archive.ubuntu.com#${MIRROR}#g            -e s#http://security.ubuntu.com#${MIRROR}#g            /etc/apt/sources.list
 ---> Using cache
 ---> 76f727c60ef8
Step 3 : RUN cat /etc/apt/sources.list
 ---> Running in 55ff5ff46467
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb /ubuntu/ trusty main restricted
deb-src /ubuntu/ trusty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb /ubuntu/ trusty-updates main restricted
deb-src /ubuntu/ trusty-updates main restricted

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb /ubuntu/ trusty universe
deb-src /ubuntu/ trusty universe
deb /ubuntu/ trusty-updates universe
deb-src /ubuntu/ trusty-updates universe

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb /ubuntu/ trusty-backports main restricted
# deb-src /ubuntu/ trusty-backports main restricted

deb /ubuntu/ trusty-security main restricted
deb-src /ubuntu/ trusty-security main restricted
deb /ubuntu/ trusty-security universe
deb-src /ubuntu/ trusty-security universe
# deb /ubuntu/ trusty-security multiverse
# deb-src /ubuntu/ trusty-security multiverse
 ---> b296354b0b9e
Removing intermediate container 55ff5ff46467
Step 5 : RUN apt-get update
 ---> Running in 7251e0ffb6d2
E: Malformed line 4 in source list /etc/apt/sources.list (URI parse)
E: The list of sources could not be read.

请注意,build-arg MIRROR 扩展为“”,这会破坏 /etc/apt sources.list 并导致更新失败。

我已经使用 Dockerfile 中的硬编码值仔细检查了 Dockerfile;

ENV MIRROR=ftp://172.17.0.2

并且一切都按预期运行,除了 docker build 失败;

One or more build-args [MIRROR] were not consumed, failing build.

我在这里遗漏了什么?

答案1

我忽略了 Dockerfile 需要相应的阿根廷入口。

答案2

代替

环境镜像=ftp://172.17.0.2

您可以使用

ARG 镜像=ftp://172.17.0.2

相关内容