Docker Community Forums

Share and learn in the Docker community.

Unexpected ADD Behaviour


(Napperley) #1

Trying to add and extract a archive (contains a single directory) to a absolute path however the Docker ADD command doesn’t extract the archive to the right path. It is a mystery where the archive has been extracted to in the Docker image. Expected the contents of the kotlin-native-linux-0.7.1.tar.gz file to be extracted to /opt/kotlin-native-linux-0.7.1. Below are the contents of the Dockerfile:

FROM openjdk:8u121-jdk-alpine
ADD https://github.com/openfaas/faas/releases/download/0.8.2/fwatchdog /usr/bin
RUN chmod +x /usr/bin/fwatchdog
ADD https://github.com/JetBrains/kotlin-native/releases/download/v0.7.1/kotlin-native-linux-0.7.1.tar.gz /opt
RUN chmod +x /opt/kotlin-native-linux-0.7.1/bin/konanc
RUN mkdir -p /app

WORKDIR /app
COPY main.kt .
RUN echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
RUN apk update
RUN apk add --no-cache bash
RUN apk add libc6-compat
RUN /opt/kotlin-native-linux-0.7.1/bin/konanc -opt -o handler main.kt

ENV fprocess="./handler.kexe"
HEALTHCHECK --interval=2s CMD [ -e /tmp/.lock ] || exit 1
CMD ["fwatchdog"]

(Napperley) #2

Appears that the ADD Docker command cannot properly handle GZip files that contain a root directory. The solution was to replace line 4 with the following:

RUN cd /opt && curl -L https://github.com/JetBrains/kotlin-native/releases/download/v${KOTLIN_NATIVE_VER}/kotlin-native-linux-${KOTLIN_NATIVE_VER}.tar.gz | tar -xz