'Cannot Normalize Nothing' Error on Docker Hub Multi-Stage Build with Shared Arg [Duplicate]
I Have a Multi-Stage Build Sharing Single Arg (To Dry out Path) Between Stages. Something Like This: Arg Build_Dir=/Build from Alpine: Latest as Build Run Apk...
I have a multi-stage build sharing single ARG (to DRY out path) between stages. Something like this:
ARG BUILD_DIR=/build
FROM alpine:latest as build
RUN apk add --no-cache gcc musl-dev
WORKDIR $BUILD_DIR
RUN echo -e '\n\
#include <stdio.h>\n\
int main (void)\n\
{ puts ("Hello, World!");}'\
>> hello.c
RUN cc -o hello hello.c
FROM alpine:latest
COPY --from=build $BUILD_DIR/hello /app
CMD ["/app"]
It gets built with no problem locally, but automated Docker Hub build fails with the following error:
Step 4/9 : WORKDIR $BUILD_DIR cannot normalize nothing
I am curious, what can cause the problem (too old build engine on Docker Hub?). And is there a better workaround than just hard-coding path in Dockerfile?
It turns out that I need to renew ARG on each step I want to reuse it. Quoting docs:
An
ARGinstruction goes out of scope at the end of the build stage where it was defined. To use an arg in multiple stages, each stage must include theARGinstruction.
The fixed Dockerfile is:
ARG BUILD_DIR=/build
FROM alpine:latest as build
ARG BUILD_DIR # <----------------------------------
RUN apk add --no-cache gcc musl-dev
WORKDIR $BUILD_DIR
RUN echo -e '\n\
#include <stdio.h>\n\
int main (void)\n\
{ puts ("Hello, World!");}'\
>> hello.c
RUN cc -o hello hello.c
FROM alpine:latest
ARG BUILD_DIR # <----------------------------------
COPY --from=build $BUILD_DIR/hello /app
CMD ["/app"]
It means that an ARG value from the code in my initial question does not even work. Interesting, that my Docker For Mac ignores the problem and silently uses empty BUILD_DIR argument for WORKDIR producing successful build. While Docker Hub automated builder fails with an error explicitly.