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.
By default, docker pull pulls a single image from the registry. A repository can contain multiple images. To pull all images from a repository, provide the -a (or --all-tags ) option when using docker pull .
A multistage build allows you to use multiple images to build a final product. In a multistage build, you have a single Dockerfile, but can define multiple images inside it to help build the final image.
With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.
A multistage Docker build process makes it possible to build out an application and then remove any unnecessary development tools from the container. This approach reduces the container's final size, but it is a complex process.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With