How to pass arguments to a Dockerfile?

流过昼夜 提交于 2020-01-11 15:04:40

问题


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


回答1:


You are looking for --build-arg and the ARG instruction. These are new as of Docker 1.9. Check out https://docs.docker.com/engine/reference/builder/#arg. This will allow you to add ARG arg to the Dockerfile and then build with docker build --build-arg arg=2.3 ..



来源:https://stackoverflow.com/questions/34254200/how-to-pass-arguments-to-a-dockerfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!