Dockerfile image build: “RUN wget” inside the Dockerfile results in partial file download, but the build completes with no errors

元气小坏坏 提交于 2021-01-28 08:32:08

问题


As stated in the title. Also, same result with curl, also same results regardless of if using the plain RUN versus EXEC mode of RUN with the wget and its args all inside [ ]

The container builds with no errors and when I run it via hijack of the entrypoint with bash I see only a few hundred bytes of the file was actually downloaded, also then from inside the running container I can then wget the complete file and run it.

Did a lot of googling and dont see anyone else with this.
???

FROM ubuntu:18.04

RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes

RUN apt-get update \
    && apt-get install \
        ca-certificates \
        jq \
        git \
        curl\
        m4 \
        make \
        patch \
        libev-dev \
        libgmp-dev \
        libhidapi-dev \
        bubblewrap \
        zip \
        unzip \
        g++ \
        pkg-config

WORKDIR /azp

ENV DEBIAN_FRONTEND=noninteractive

RUN ["curl", "-s", "-o", "/usr/local/bin/opam", "https://github.com/ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux"]

RUN chmod a+x /usr/local/bin/opam

ENTRYPOINT ["bash"]

回答1:


The issue is with the curl command here

RUN ["curl", "-s", "-o", "/usr/local/bin/opam", "https://github.com/ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux"]

With this command it downloads an HTML page instead of the binary.

Doing a verbose request, you can see that the request is being redirected

curl -v -o /usr/local/bin/opam https://github.com/ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux
...
> GET /ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux HTTP/1.1
> Host: github.com
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 302 Found
< date: Tue, 14 Apr 2020 19:33:11 GMT
< content-type: text/html; charset=utf-8
< server: GitHub.com
< status: 302 Found
...

In such cases, option -L must be passed to the curl request

-L/--location (HTTP/HTTPS) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place.

Modify your curl command as

RUN ["curl", "-sL", "-o", "/usr/local/bin/opam", "https://github.com/ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux"]

Or use wget

RUN ["wget", "https://github.com/ocaml/opam/releases/download/2.0.6/opam-2.0.6-x86_64-linux"]


来源:https://stackoverflow.com/questions/61197526/dockerfile-image-build-run-wget-inside-the-dockerfile-results-in-partial-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!