Reduce docker-compose files with YAML magic
Last update: Sep 22, 2020
If you find yourself writing long docker-compose files because you need to specify the same things over and over again inside of the single services: fear no more!
Without further ado:
version: '3.4' # min version 3.4 x-default: &default restart: always env_file: .env services: web: <<: *default image: node # blablabla db: <<: *default image: postgres
Thats it! Now both
db inherit the properties of
x- prefix is a docker specific thing and is required. YAML support references also without the prefix. Also note that version 3.4 or higher is required.