Compose: Allow for adding extra_hosts to another container

Created on 31 Jan 2018  路  3Comments  路  Source: docker/compose

Let me know if this isnt the way i should be doing this, but i have the following config:

version: '2'
services:
    webserver:
        image: abiosoft/caddy
        ports:
            - 80:80
        // ... Some other stuff
     api:
         // ... Normal stuff
     www:
         // ... Normal stuff
         extra_hosts:
             - "dev.api.example.com:webserver"

The webserver has multiple vhosts in it, and nothing defaulted, so i can't use webserver. I cant expose the port on the api container, as its not a webserver.

kinquestion

Most helpful comment

I don't think that'll work. Use network aliases instead.

All 3 comments

I don't think that'll work. Use network aliases instead.

Ah ha, that works! Thank you!

version: '2'
services:
    webserver:
        image: abiosoft/caddy
        ports:
            - 80:80
        networks:
          some-network:
            aliases:
             - dev.api.example.com
     api:
         // ... Normal stuff
         networks:
          some-network
     www:
         // ... Normal stuff
         networks:
          some-network
Was this page helpful?
0 / 5 - 0 ratings