invalid reference format when building a Docker Image

Viewed 11225

I have the following lines in a Dockerfile:

ARG SOMEARGUMENT
COPY --from=$SOMEARGUMENT /some/path/goes/here

where SOMEARGUMENT could be either "some/repository:1.1.1" or "some/repository:2.2.2"

But when trying to build I always get the error:

invalid reference format: repository name must be lowercase

So it is obvious that the argument passed when building the image (i.e. SOMEARGUMENT) is not being resolved.

Is it actaully possible to do something like this in a Dockerfile?

Thanks.

2 Answers

Expanding on Siyu answer.

A possible solution to your questions can be the following:

Dockerfile:

ARG SOMEARGUMENT
ARG SOMEVERSION=latest

FROM ${SOMEARGUMENT}:${SOMEVERSION} as thebase
RUN echo "This is a test" > /test.txt


FROM alpine:latest
COPY --from=thebase /test.txt /success.txt

CMD cat /success.txt

Command to build:

docker build --build-arg SOMEARGUMENT=alpine --tag test .
Related