Define target for multi-stage Dockerfile
When configuring an application, we should be able to define the target to work properly with multi-staged Dockerfile
https://docs.docker.com/develop/develop-images/multistage-build/
Why is it a must have ?
We can easily use the same Dockerfile for local environment and remote environments
We can use the same image for different applications
It improves the cache usability
A simple use case
Let's say we have a Laravel application and we want to have three apps:
The
php-fpmapp (contains the full application withphp-fpmrunning)The
nginxapp (contains only the public folder of the app withnginxrunning)The
workerapp (contains the full application withphp artisan worker:runcommand)
Without the multi-stage feature, we must have three Dockerfiles where we could only have one:
FROM php:fpm-alpine AS build
// Build the app
FROM build AS app
CMD ["php-fpm"]
FROM build AS worker
CMD ["php artisan worker:run"]
FROM nginx:latest AS nginx
COPY --from=build /var/www/html/public /var/www/html/public
The we could just define the target (app, worker and nginx)
Log in to comment and vote
Comments1
Alessandro Carrano
Apr 24, 2025
This has been released! you can now specify the target of your multi-stage dockerfile