使用多阶段docker文件输出多个图像 [英] Use multi-stage docker files for outputting multiple images

查看:59
本文介绍了使用多阶段docker文件输出多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的docker功能是在dockerfile中执行类似的操作

A new docker feature is to do something like this in the dockerfile

FROM php7-fpm as build
...

FROM build AS test
...

FROM test AS staging
...

据我所知,最后一个FROM语句标记了最终的输出图像.怎么可能从一个中间图像中得到两个最终图像?

As far as i know, the last FROM statement marks the final output image. How is it possible to have two final images from one intermdiate image?

喜欢

...
FROM build AS test
...
FROM test AS staging
...
FROM test AS prod

不应丢弃测试,暂存和生产.我想将它们检入到存储库中.

Test, staging and prod should not be discarded. I want to check in them into the repository.

推荐答案

您可以在某个阶段停止构建并根据需要标记它们.

You can stop the build at a certain stage and tag them as you want.

docker build --target test -t starx/test:latest .
docker build --target staging -t starx/staging:latest .
docker build --target prod -t starx/prod:latest .

通过这种方式,您可以拥有不同的图像,并且可以分别推动每个图像.

This way, you have different images and you can push each image individually.

这篇关于使用多阶段docker文件输出多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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