Why do I get "unzip: short read" when I try to build an image from Dockerfile? Why do I get "unzip: short read" when I try to build an image from Dockerfile? docker docker

Why do I get "unzip: short read" when I try to build an image from Dockerfile?


Somehow, curl on alpine linux distro can't set cookie headers correctly while downloading jce zip file. It seems it downloads a zip file but in fact it is an html error page. If you view the file you can see that it is an html file. I've used wget instead of curl and it successfully downloaded file. Then unzip operation worked as expected.

FROM openjdk:8-jdk-alpineRUN  apk update && apk upgrade && apk add netcat-openbsdRUN mkdir -p /usr/local/configserverRUN cd /tmp/ && \    wget 'http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip' --header "Cookie: oraclelicense=accept-securebackup-cookie" && \    unzip jce_policy-8.zip && \    rm jce_policy-8.zip && \    yes |cp -v /tmp/UnlimitedJCEPolicyJDK8/*.jar /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/ADD @project.build.finalName@.jar /usr/local/configserver/ADD run.sh run.shRUN chmod +x run.shCMD ./run.sh


I'm find solved link

FROM openjdk:8-jdk-alpineRUN  apk update && apk upgrade && apk add netcat-openbsd && apk add curlRUN mkdir -p /usr/local/configserverRUN cd /tmp/ && \    **curl -L -b "oraclelicense=a" http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip -O** && \    unzip jce_policy-8.zip && \    rm jce_policy-8.zip && \    yes |cp -v /tmp/UnlimitedJCEPolicyJDK8/*.jar /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/ADD @project.build.finalName@.jar /usr/local/configserver/ADD run.sh run.shRUN chmod +x run.shCMD ./run.sh


It's possible your jce_policy-8.zip archive is being recognized as a compressed archive and expanded by the ADD instruction. If so, you can skip unzipping on the next line. Or, switch to the COPY instruction, which does no special processing of local archives.

In general, I recommend always using the COPY instruction to bring in files and directories from the build context. Only use ADD when you specifically want the extra unpacking behaviour.