1

I have the following 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

and I got:

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

I found a StackExchange thread with the same problem & understand from Docker ADD documentation that

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.

However, I read it carefully several times that

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

and in my case I don't have trailing slash. I tried setting the <src> to /tmp/ like this

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

I got:

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

I'm confused. Did I miss something? I'm using macOS 10.12.6 with

Docker version 17.06.0-ce, build 02c1d87
docker-compose version 1.14.0, build c7bdf9e
docker-machine version 0.12.0, build 45c69ad
1

I modified your Dockerfile to add an ls -Rlh /tmp before the tar and saw this:

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

So, it seems, Docker recognised that the file is a tarball and did the extraction for you. You could probably do just:

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

Which gives me this:

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

This does seem to contradict the docs:

  • 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.
  • Thanks for answering this quickly. So do you think it's okay & safe to download it directly to /usr/local/bin/? Do you think this behaviour will continue or they'll follow the docs and fix this? – Dida Aug 10 '17 at 11:43
  • @Dida I think you should file a bug report - either they'll fix the docs or the code. At any rate, I could reproduce this behaviour on both Linux and Mac. – muru Aug 10 '17 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.