Use multi-stage docker files for outputting multiple images

纵饮孤独 提交于 2021-02-06 10:12:37

问题


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

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?

Like

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


回答1:


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.



来源:https://stackoverflow.com/questions/49028097/use-multi-stage-docker-files-for-outputting-multiple-images

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