Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARG substitution in RUN command not working for Dockerfile

In my Dockerfile I have the following:

ARG a-version RUN wget -q -O /tmp/alle.tar.gz http://someserver/server/$a-version/a-server-$a-version.tar.gz && \     mkdir /opt/apps/$a-version 

However when building this with:

--build-arg http_proxy=http://myproxy","--build-arg a-version=a","--build-arg b-version=b" 

Step 10/15 : RUN wget... is shown with $a-version in the path instead of the substituted value and the build fails.

I have followed the instructions shown here but must be missing something else.

My questions is, what could be causing this issue and how can i solve it?

like image 710
user3139545 Avatar asked Jun 08 '17 14:06

user3139545


People also ask

How do I pass ARG in Dockerfile?

ARG instruction defines a variable that can be passed at build time. Once it is defined in the Dockerfile you can pass with this flag --build-arg while building the image. We can have multiple ARG instruction in the Dockerfile. ARG is the only instruction that can precede the FROM instruction in the Dockerfile.

Can an ARG variable on Dockerfile be used by the running container?

Running containers can't access values of ARG variables. This also applies to CMD and ENTRYPOINT instructions which just tell what the container should run by default.

What is Arg and ENV in Dockerfile?

From Dockerfile reference: The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag. The ENV instruction sets the environment variable <key> to the value <value> .

How do I create a Run command in Dockerfile?

The basic syntax for the command is: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] You can run containers from locally stored Docker images. If you use an image that is not on your system, the software pulls it from the online registry.


1 Answers

Another thing to be careful about is that after every FROM statements all the ARGs get collected and are no longer available. Be careful with multi-stage builds.

You can reuse ARG with omitted default value inside FROM to get through this problem:

ARG VERSION=latest FROM busybox:$VERSION ARG VERSION RUN echo $VERSION > image_version 

Example taken from docs: https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact

like image 197
Hongtao Yang Avatar answered Sep 26 '22 06:09

Hongtao Yang