如何传递参数到Dockerfile? [英] How to pass arguments to a Dockerfile?

查看:251
本文介绍了如何传递参数到Dockerfile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Dockerfile 中使用RUN指令来安装rpm

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

RUN yum -y install samplerpm-2.3

但是,我想传递值2.3作为论据。
我的RUN指令应该看起来像:

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

其中 $ arg = 2.3

推荐答案

您正在寻找 - build-arg ARG 指令。这些是Docker 1.9的新功能。请查看 https://docs.docker.com/engine/reference/builder/#arg 。这将允许您将 ARG arg 添加到 Dockerfile 中,然后使用 docker build构建 - -build-arg arg = 2.3。

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 ..

这篇关于如何传递参数到Dockerfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆