Reputation: 2338
I have a Dockerfile that needs to get base image tag from the command line and load it dynamically, but I am getting this error with this command line.
$ docker build --network=host --build-arg sample_TAG=7.0 --rm=true .
Step 9/12 : FROM "${sample_TAG}"
base name ("${sample_TAG}") should not be blank
The Dockerfile:
FROM maven:3.6.1-jdk-8 as maven-build
ARG sample_TAG
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
WORKDIR /apps/sample-google
COPY . /apps/sample-google
RUN mvn clean package
RUN echo "image tag is ${sample_TAG}"
FROM $sample_TAG
VOLUME /apps
RUN mkdir /apps/sample-google
COPY --from=maven-build /apps/sample-google/target /apps/sample-google
The echo line prints 'latest' string correctly, but it fails in 'FROM $sample_TAG' line.
Upvotes: 8
Views: 5954
Reputation: 1839
change to
ARG sample_TAG
FROM maven:3.6.1-jdk-8 as maven-build
...
FROM $sample_TAG
Upvotes: 1
Reputation: 59946
For that, you need to define Global ARGs and better to have some default value and override it during build time.
ARG sample_TAG=test
FROM maven:3.6.1-jdk-8 as maven-build
ARG sample_TAG
WORKDIR /apps/sample-google
RUN echo "image tag is ${sample_TAG}"
FROM $sample_TAG
VOLUME /apps
RUN mkdir /apps/sample-google
Upvotes: 10