How to run multiple WordPress instances using docker?

You can define a base docker-compose.yml and define environment specific docker-compose yml files that override or extend the base declaration: https://docs.docker.com/compose/extends/#example-use-case

Another option, I realy like and prefer over the override/extend is to declare environment specifc values as variable and use envsubst (from the os gettext package) to actualy render values inside the compose.yml. Appart from not beeing able to conditionaly render content blocks, this approach has no limitation about what can be substituted.

It is important to export all placeholdes into the shell environment, because envsubst will only replace those in the input file:
Assumed you use a variable called ${VAR_A} as a placeholder in your yml. Then execute export VAR_A=myvalue && envsubst < my_docker_compose_template.yml | docker-compose -f - up -d to render the value into the yml and let docker-compose use it from stdin.

Does that make sense?

1 Like