題 docker build --build-arg丟失值並擴展為空字符串


使用docker版本1.9.0

我有一個docker容器,提供了一個ubuntu可信鏡像(可信鏡像)。我正在嘗試構建第二個容器,並希望它從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.

我在這裡想念的是什麼?


3
2017-11-12 04:27


起源




答案:


我錯過的是需要相應的Dockerfile ARG 條目。


6
2017-11-13 14:42





代替

ENV MIRROR =ftp://172.17.0.2

您可以使用

ARG MIRROR =ftp://172.17.0.2


2
2018-04-08 12:16