here is the docker-compose.yml I would like to achieve:
version: "3.4"
services:
service1:
image: dorowu/ubuntu-desktop-lxde-vnc
service2:
build:
context: .
environment:
- DISPLAY=[use env variable DISPLAY of service1]
Is there a way in docker compose to tell service2 that the value of env variable DISPLAY must be the same as the env variable DISPLAY defined in service1 ?
Edit
The DISPLAY env var is set in dorowu/ubuntu-desktop-lxde-vnc directly in the Dockerfile.
It's not a duplicate of Re-using environment variables in docker-compose.yml because the question asked how to write a common env variables for differents services.
In my case I don't want to explicitly write a common variables (with a .env file for example) but I want to set the env variable DISPLAY of service2 to the same value as DISPLAY in service 1 without having to rewrite it in a .env file.
For example if I wanted my service2 to have the same DISPLAY as my host I could write:
version: "3.4"
services:
service1:
image: dorowu/ubuntu-desktop-lxde-vnc
service2:
build:
context: .
environment:
- DISPLAY=$DISPLAY
Now in this case I'm looking for something like:
version: "3.4"
services:
service1:
image: dorowu/ubuntu-desktop-lxde-vnc
service2:
build:
context: .
environment:
- DISPLAY=service1:$DISPLAY