Compose: Add support for build-time extra_hosts

Created on 18 Oct 2017  路  12Comments  路  Source: docker/compose

I'm having an issue with extra_hosts on compose.

$> docker -v               
Docker version 17.06.0-ce, build 02c1d87
$> docker-compose -v 
docker-compose version 1.16.1, build 6d1ac219

The --add-host option works correctly with docker build but the extra_hosts of docker-compose doesn't.
I'm using a 3.3 version ok Compose file, here is a sample

version: '3.3'

services:
  my_service:
    build:
      context: ./some_folder
      args:
        ARG1: $ARG1
        ARG2: $ARG2
    extra_hosts:
      - "my.local.network.url:XXX.XXX.XXX.XXX"
    environment:
      SOME_VAR: $SOME_VAR
    volumes:
      - ./folder1:/folder1

My volumes are not interfering with /etc/hosts or anything like that.
Can anyone tell me if I'm doing anything wrong ?

arebuild kinparity kinquestion

Most helpful comment

Is there any news in this regards? When the extra_hosts will finally add the values to /etc/hosts, it would be highly appreciated!

All 12 comments

This is working as intended – the extra_hosts field is runtime configuration for your service, it doesn't affect builds.

I see, my bad then. Can you tell me how I am supposed to reproduce the behaviour of docker build --add-host with docker compose then ?

Unfortunately, that feature hasn't yet been implemented in Compose.

Well, that's inconvenient !

Thanks for your time anyway :)

@shin- is there an open issue for implementing extra_hosts at build time?

Well there's this one :)

I spent two hours this afternoon trying to get that to work, while sorting out that it was not my usage nor my installation (which I just updated to Ubuntu 17.10 with several old versions of docker-compose) that was the problem. The _actual_ thing I want to solve is to facilitate Maven (we do Java) to access a caching proxy running on the host to avoid downloading half the internet every time an image needs to be rebuild. I need a reliable mechanism to refer to the host and thought this might work. I am relatively new to Docker so there might be a trick I have overlooked? I need this to work on Mac and Linux for now, and Windows in the long run.

@shin- there is no such option in version 3 config file. Why?

Does someone know some work arounds for this?

Is there any news in this regards? When the extra_hosts will finally add the values to /etc/hosts, it would be highly appreciated!

I open new issue #6138

Issue moved to https://github.com/docker/cli repo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

squeaky-pl picture squeaky-pl  路  3Comments

saulshanabrook picture saulshanabrook  路  3Comments

leiblix picture leiblix  路  3Comments

CrimsonGlory picture CrimsonGlory  路  3Comments

HackerWilson picture HackerWilson  路  3Comments