动态Docker基本映像 [英] Dynamic Docker base image

查看:66
本文介绍了动态Docker基本映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dockerfile,需要从命令行获取基本图像标签并动态加载它,但是在此命令行中却遇到此错误。

I have a Dockerfile that needs to get base image tag from the command line and load it dynamically, but I am getting this error with this command line.

$ docker build --network=host --build-arg sample_TAG=7.0  --rm=true .

Step 9/12 : FROM "${sample_TAG}"
base name ("${sample_TAG}") should not be blank

Dockerfile:

The Dockerfile:

FROM maven:3.6.1-jdk-8 as maven-build

ARG sample_TAG

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8


WORKDIR /apps/sample-google


COPY . /apps/sample-google


RUN mvn clean package



RUN echo "image tag is ${sample_TAG}"

FROM $sample_TAG


VOLUME /apps

RUN mkdir /apps/sample-google
COPY --from=maven-build  /apps/sample-google/target /apps/sample-google

回显行打印最新字符串正确,但在 FROM $ sample_TAG行中失败。

The echo line prints 'latest' string correctly, but it fails in 'FROM $sample_TAG' line.

推荐答案

为此,您需要定义Global ARG最好具有一些默认值,并在构建时覆盖它。

For that, you need to define Global ARGs and better to have some default value and override it during build time.

ARG sample_TAG=test
FROM maven:3.6.1-jdk-8 as maven-build
ARG sample_TAG
WORKDIR /apps/sample-google
RUN echo "image tag is ${sample_TAG}"
FROM $sample_TAG
VOLUME /apps
RUN mkdir /apps/sample-google

这篇关于动态Docker基本映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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