We could use env vars for the WordPress and PHP versions to build the desired image, something like:
ARG WP_VERSION=5
ARG PHP_VERSION=8-apache
ARG BASE_IMAGE=wordpress:${WP_VERSION}-php${PHP_VERSION}
# $BASE_IMAGE will be something like `wordpress:5.9.1-php8.0-apache`
# and would fallback to wordpress:5-php8-apache
FROM $BASE_IMAGE
Can these pull from the environment? Config in package.json?
References: