How to pass arguments to a Dockerfile?

DockerDockerfileDocker ComposeDocker RegistryDockerhub

Docker Problem Overview


I am using RUN instruction within a Dockerfile to install a rpm

RUN yum -y install samplerpm-2.3

However, I want to pass the value "2.3" as an argument. My RUN instruction should look something like:

RUN yum -y install samplerpm-$arg

where $arg=2.3

Docker Solutions


Solution 1 - Docker

As of Docker 1.9, You are looking for --build-arg and the ARG instruction.

Check out this document for reference. This will allow you to add ARG arg to the Dockerfile and then build with

docker build --build-arg arg=2.3 .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmeallhourView Question on Stackoverflow
Solution 1 - DockerAndy ShinnView Answer on Stackoverflow