Dockerfile: 위치 추가URL은 다운로드한 파일 대신 디렉터리를 생성합니다.

Dockerfile: 위치 추가URL은 다운로드한 파일 대신 디렉터리를 생성합니다.

다음 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

알겠어요:

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

동일한 문제가 있는 StackExchange 스레드를 찾아서 이해했습니다.Docker 추가 문서저것

ADD ../something /something첫 번째 단계 docker build는 컨텍스트 디렉터리(및 하위 디렉터리)를 docker 데몬으로 보내는 것이기 때문에 그렇게 할 수 없습니다 .

하지만 몇 번이나 주의 깊게 읽어보니 깨달았습니다.

<src>URL이고 후행 슬래시로 끝나지 않으면 <dest>파일이 URL에서 다운로드되어 에 복사됩니다 <dest>.

<src>URL이고 후행 슬래시로 끝나는 경우 <dest>파일 이름은 URL에서 유추되고 파일은 에 다운로드됩니다 <dest>/<filename>.

내 경우에는 후행 슬래시가 없습니다. <src>이렇게 /tmp/설정 해봤는데

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

나는 가지고있다:

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

혼란스러워요. 내가 놓친 게 무엇입니까? 저는 macOS 10.12.6을 사용하고 있습니다.

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

ls -Rlh /tmptar 앞에 하나를 추가 하도록 Dockerfile을 수정했고 다음을 확인했습니다.

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

그래서 Docker는 파일이 tarball임을 인식하고 이를 추출하는 것 같습니다. 아마도 다음과 같이 할 수 있을 것입니다:

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

이것은 나에게 다음을 제공합니다:

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

이는 문서와 모순되는 것 같습니다.

  • 만약 <src>그것이라면현지의tar는 인식된 압축 형식(identity, gzip, bzip2 또는 xz)으로 아카이브한 다음 디렉터리에 추출합니다. 리소스는 다음에서 제공됩니다.외딴URL은 압축 해제되지 않습니다.

관련 정보