将参数传递给父 Dockerfile [英] Pass arguments to parent Dockerfile
问题描述
有没有办法使用父 docker 镜像中定义的参数?
Is there any way to use the arguments defined in the parent docker image?
给定以下子 Dockerfile
Given the following child Dockerfile
FROM jenkins
USER ${user}
RUN echo "${user}"
摘自父Dockerfile
FROM openjdk:8-jdk
ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000
推荐答案
构建参数 不会持久化在映像中,因此它们在构建 FROM
父映像中将不可用.
Build arguments are not persisted in images, so they will not be available in builds FROM
a parent image.
与 ARG 指令不同,ENV 值始终保留在构建的映像中.
Unlike an ARG instruction, ENV values are always persisted in the built image.
ARG 变量不会像 ENV 变量那样持久化到构建的映像中.
ARG variables are not persisted into the built image as ENV variables are.
参数可以通过将它们存储在某个地方来持久化,最简单的地方是在环境变量中.
The arguments can be persisted by storing them somewhere, the easiest place is in an environment variable.
ARG IMAGE_USER=jenkins
ENV IMAGE_USER=$IMAGE_USER
然后子映像中的所有 RUN
步骤都可以访问其环境中的 IMAGE_USER
.
All RUN
steps in the child image will then have access to IMAGE_USER
in their environment.
这篇关于将参数传递给父 Dockerfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!