TL;DR: No, it is not possible
First of all, you have typos in your docker-compose, please copy the whole docker-compose next time. Here is mine corrected (I didn't wanted to edit your question) and extended to be testable:
version: '2.4'
x-base-template: &base-template
image: alpine
command: env
environment:
- FOO=BAR
x-custom-template-1: &custom-template1
<<: *base-template
environment:
- FOO2=BAR2
services:
service-1:
<<: *custom-template1
This setup will completely override the environment setting, so only FOO2 is set, i suppose that's why you asking.
I don't know where you picked up the plus+ syntax, but i can't find anything about it. The only place i did find + is in https://yaml.org/refcard.html, but there is not mentioned with arrays at all. That's for strings.
You cannot merge arrays at all, but you can use key: value syntax for environment, and that can be merged this way:
version: '2.4'
x-base-environment: &base-environment
FOO: BAR
x-base-template: &base-template
image: alpine
command: env
environment: *base-environment # This is only necessary if you want variables in base-template
x-custom-template-1: &custom-template1
<<: *base-template
environment:
<<: *base-environment
FOO2: BAR2
services:
service-1:
<<: *custom-template1
The merging we are using, the Merge Key Language-Independent Type, doesn't support nested merging. That means that key is either picked from one object, or the other, no combination. And that's intended desing, it's good behaviour most of the time. Sad thing is, there is no yaml feature (any i know of), that supports nested merging, so simple answer to you questions is "No, it is not possible"
Sidenote: GitLab tried to solve this for their CI config with their proprietary extends which supports
reverse deep merge based on the keys