Dockerfile: ADICIONE onde src é URL cria um diretório em vez do arquivo baixado

1

Eu tenho o seguinte Dockerfile:

FROM node:alpine

ENV HUGO_VERSION 0.26
ENV HUGO_BINARY hugo_${HUGO_VERSION}_linux-64bit

# Install node
RUN apk add --update \
        git py-pygments tar \
        && rm -rf /var/cache/apk/*

# Download and Install hugo
ADD https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/${HUGO_BINARY}.tar.gz /tmp/${HUGO_BINARY}.tar.gz
RUN tar xzf /tmp/${HUGO_BINARY}.tar.gz -C /usr/local/bin/ \
        && rm /tmp/${HUGO_BINARY}.tar.gz

e eu recebi:

tar (child): /tmp/hugo_0.26_linux-64bit.tar.gz: Cannot open: No such file or directory

Eu encontrei um thread do StackExchange com o mesmo problema & entender de documentação do Docker ADD que

you cannot ADD ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

No entanto, eu li cuidadosamente várias vezes que

If <src> is a URL and <dest> does not end with a trailing slash, then a file is downloaded from the URL and copied to <dest>.

If <src> is a URL and <dest> does end with a trailing slash, then the filename is inferred from the URL and the file is downloaded to <dest>/<filename>.

e no meu caso não tenho barra final. Eu tentei definir o <src> para /tmp/ como este

ADD https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/${HUGO_BINARY}.tar.gz /tmp/
RUN tar xzf /tmp/${HUGO_BINARY}.tar.gz -C /usr/local/bin/ \
        && rm /tmp/${HUGO_BINARY}.tar.gz

Eu tenho:

tar (child): /tmp/hugo_0.26_linux-64bit.tar.gz: Cannot open: No such file or directory

Estou confuso. Perdi alguma coisa? Estou usando o macOS 10.12.6 com

Docker version 17.06.0-ce, build 02c1d87
docker-compose version 1.14.0, build c7bdf9e
docker-machine version 0.12.0, build 45c69ad
    
por Dida 10.08.2017 / 04:21

1 resposta

1

Eu modifiquei o seu Dockerfile para adicionar um ls -Rlh /tmp antes do tar e vi isso:

Step 5/5 : RUN ls -Rlh /tmp/ && tar xzf /tmp/${HUGO_BINARY}.tar.gz -C /usr/local/bin/         && rm /tmp/${HUGO_BINARY}.tar.gz
 ---> Running in deea1f3a4b1a
/tmp/:
total 4
drwxr-xr-x    2 root     root        4.0K Aug 10 05:25 hugo_0.26_linux-64bit.tar.gz

/tmp/hugo_0.26_linux-64bit.tar.gz:
total 11976
-rw-r--r--    1 root     root       10.2K Jun 17 08:06 LICENSE.md
-rw-r--r--    1 root     root        6.2K Jul 18 08:50 README.md
-rwxr-xr-x    1 root     root       11.7M Aug  7 07:09 hugo

Parece que o Docker reconheceu que o arquivo é um tarball e fez a extração para você. Você provavelmente poderia fazer apenas:

# Download and Install hugo
ADD https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/${HUGO_BINARY}.tar.gz /usr/local/bin/

O que me dá isso:

Step 5/5 : RUN ls -Rlh /usr/local/bin/
 ---> Running in 6f6cabfbbde8
/usr/local/bin/:
total 47596
-rw-r--r--    1 root     root       10.2K Jun 17 08:06 LICENSE.md
-rw-r--r--    1 root     root        6.2K Jul 18 08:50 README.md
-rwxr-xr-x    1 root     root       11.7M Aug  7 07:09 hugo
-rwxr-xr-x    1 root     root       34.8M Jul 21 18:20 node
lrwxrwxrwx    1 root     root          38 Jul 21 18:20 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx    1 root     root          38 Jul 21 18:20 npx -> ../lib/node_modules/npm/bin/npx-cli.js
lrwxrwxrwx    1 root     root          18 Jul 21 18:21 yarn -> /opt/yarn/bin/yarn
lrwxrwxrwx    1 root     root          18 Jul 21 18:21 yarnpkg -> /opt/yarn/bin/yarn

Isso parece contradizer os documentos:

  • If <src> is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources from remote URLs are not decompressed.
    
por 10.08.2017 / 07:36

Tags