docker build --build-arg perde valor e se expande para string vazia

3

Usando a versão do Docker 1.9.0

Eu tenho um contêiner docker fornecendo um espelho confiável do Ubuntu (espelho fiel). Eu estou tentando construir um segundo contêiner e quero que ele atualize e instale pacotes do espelho confiável.

Meu Dockerfile para o segundo container tem:

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

Eu passo as informações do MIRROR para a compilação do docker usando opção --build-arg , assim;

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

Quando isso é executado

+++ 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.

Note que o build-arg MIRROR se expande para "", o que corrompe o arquivo / etc / apt sources.list e faz com que a atualização falhe.

Eu verifiquei novamente o Dockerfile usando um valor codificado no Dockerfile;

ENV MIRROR=ftp://172.17.0.2

e tudo é executado conforme o esperado, EXCETO a compilação do docker falha com;

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

O que estou perdendo aqui?

    
por CAB 12.11.2015 / 05:27

2 respostas

6

O que eu perdi foi o Dockerfile exigindo uma entrada ARG correspondente.

    
por 13.11.2015 / 15:42
2

Em vez de

ENV MIRROR=ftp://172.17.0.2

Você pode usar

ARG MIRROR=ftp://172.17.0.2

    
por 08.04.2016 / 14:16