问题
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