Can I set a variable in docker-compose yml file for more clear code ?
For example if there is a value that I use more than once and I want to keep it with one declaration
Like :
version: '2.4'
ValueToPassFromVariable: '2020-10-10 12:00:00'
services:
img1:
image: img1
build:
context: .
args:
- STARTDATE=ValueToPassFromVariable
dockerfile: DockerFileImg1
img2:
image: img2
build:
context: .
args:
- STARTDATE=ValueToPassFromVariable
dockerfile: DockerFileImg2
I want to save some value in ValueToPassFromVariable and use it few time, can i do something like this ?
If you update to a newer version of docker-compose, you can get generic reuse by using extension fields:
version: "3.8"
x-args: &args
args:
- STARTDATE=2020-10-10 12:00:00
services:
img1:
image: img1
build:
context: .
<< : *args
dockerfile: DockerFileImg1
img2:
image: img2
build:
context: .
<< : *args
dockerfile: DockerFileImg2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With