Docker Community Forums

Share and learn in the Docker community.

Docker-compose.yml how to implement value redundancy


(Anavalcyrious) #1

example docker compose file

version: '3.0'
services:
  someapi1:
    image: api1image
    extra_host:
      - myhost1.dev.com: 10.10.10.1
      - myhost2.dev.com: 10.10.10.2
  someapi2:
    image: api2image
    extra_host:
      - myhost1.dev.com: 10.10.10.1
      - myhost2.dev.com: 10.10.10.2

so in the example above, how do I implement extra_host without having to change everything 1 by 1?
is there a way I can declare extra_host as a environment variable even if it is an array? so I can reuse it again and again.

my use-case is that we have a background api engine that we don’t want to put on docker, and we want someapi1 and someapi2 to be able to make a curl request to myhost1.dev.com and myhost2.dev.com

as for why we don’t want to put myhost1.dev.com in a container, Its what our dev team lead wants, I have no power to object over it.

also, im using windows container by the way and extra_hosts doesn’t seem to work


(Think) #2

have a look at https://en.wikipedia.org/wiki/YAML#Advanced_components

Yaml allows you to define blocks which you later can reuse. So define your extrahost-list once and then use it for all your services.
Is this what you want? Does it help you?