Hello,
I am using multi-stage builds and I have a case where I would like to use a different image for development vs production, basically, something like:
FROM devilbox/php-fpm:${PHP_VERSION:-"8.2-work"} AS php
where PHP_VERSION would be a ENV var set before calling the docker command.
So far I tried Use environment variables | Docker Docs but that won’t work in the FROM command. I also tried passing --build-arg
to the build command, but same result.
I only had success by doing two different build stages, one for dev and one for production, and reference those in the right docker-compose.yml file, i.e:
# Dockerfile:
FROM devilbox/php-fpm:8.2-work AS php_dev
...
FROM devilbox/php-fpm:8.2-prod AS php_prod
DEV: docker-compose.override.yml:
php:
container_name: php
build:
context: .
target: php_dev
PROD: docker-compose.prod.yml:
php:
container_name: php
build:
context: .
target: php_prod
Any idea how to go about this?
Thanks.