You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@resouer Yes. In our somewhat complex network setup, we need to edit the host file. We found a workaround here; http://jasonincode.com/customizing-hosts-file-in-docker/ but surely there must be a better way. --add-host=[] would fix this. It also looks like (see other tickets) many people are looking for this. (Hence --add-host=[] was added to docker run, here it is available today.). Having the same for docker build would be fantastic, thank you
In general I'm +1 with adding support for things like resource management for the builds, however add-host is specifically something that could make a build work on one host and not on another, and you can't tell why by just looking at the source (Dockerfile).
If you need resolution to these hosts, I'd suggest setting up a DNS server to handle these requests transparently.
So basically, I would have to -1 this one for now, I think.
however add-host is specifically something that could make a build work on one host and not on another, and you can't tell why by just looking at the source (Dockerfile).
@cpuguy83 playing devils advocate here; having a special DNS on one host and not on another, would also break the build on one host; looking at the Dockerfile also wouldn't explain why it breaks on that host but succeeds on another?
danielwegener, ZihengJiang, peraage, mgomezch, BrendanBall and 7 more
@RoelVdP My point is, if you want to modify /etc/hosts, do it as part of the build at the beginning of your RUN command.
If the fact that the build isn't working due to needing hosts is an exception to the rule, then yes, fire up a DNS server like github.com/tianon/rawdns to handle this scenario transparently to the build.
@thaJeztah I get your point. And having --add-host would probably be somewhat equivalent of firing up a DNS server... but a feature once added is abused... which makes me (personally) less comfortable with this one in particular.
For anyone who's reading this; thanks to @cpuguy83 we now have the following workaround;
RUN echo ${IP} ${NAME} >> /etc/hosts; ${COMMAND}
The command HAS to be on the same line as the hosts addition (it will not be there the next RUN command), but at least this can be used for each command where needed. Definitely easier then the workaround at http://jasonincode.com/customizing-hosts-file-in-docker/
@cpuguy83 Thanks. While a nice workaround, it would still be great to have the --add-host solution mentioned earlier?
raanand-home, dklotz, vingrad, sporting, herberthamaral and 10 moreBill, herberthamaral, Glavin001, groovili, vasya10 and 2 more
Activity
resouer commentedon Jan 30, 2015
@RoelVdP Any reason to why you try to do this ?
RoelVdP commentedon Jan 30, 2015
@resouer Yes. In our somewhat complex network setup, we need to edit the host file. We found a workaround here; http://jasonincode.com/customizing-hosts-file-in-docker/ but surely there must be a better way.
--add-host=[]
would fix this. It also looks like (see other tickets) many people are looking for this. (Hence--add-host=[]
was added todocker run
, here it is available today.). Having the same fordocker build
would be fantastic, thank youcpuguy83 commentedon Jan 30, 2015
In general I'm +1 with adding support for things like resource management for the builds, however add-host is specifically something that could make a build work on one host and not on another, and you can't tell why by just looking at the source (Dockerfile).
If you need resolution to these hosts, I'd suggest setting up a DNS server to handle these requests transparently.
So basically, I would have to -1 this one for now, I think.
thaJeztah commentedon Jan 31, 2015
@cpuguy83 playing devils advocate here; having a special DNS on one host and not on another, would also break the build on one host; looking at the Dockerfile also wouldn't explain why it breaks on that host but succeeds on another?
RoelVdP commentedon Feb 2, 2015
A DNS server needs to be installed to cover the (fairly basic) functionality of adding a single host IP/name to the hosts file?
cpuguy83 commentedon Feb 2, 2015
@RoelVdP My point is, if you want to modify /etc/hosts, do it as part of the build at the beginning of your RUN command.
If the fact that the build isn't working due to needing hosts is an exception to the rule, then yes, fire up a DNS server like github.com/tianon/rawdns to handle this scenario transparently to the build.
@thaJeztah I get your point. And having --add-host would probably be somewhat equivalent of firing up a DNS server... but a feature once added is abused... which makes me (personally) less comfortable with this one in particular.
RoelVdP commentedon Feb 3, 2015
@cpuguy83 It is not possible to do it using RUN command/as part of the build; Docker makes this file R/O....
(except when using the complex solution mentioned in the url above http://jasonincode.com/customizing-hosts-file-in-docker/)
It would be great to have this functionality, just like it is available in Docker run.
cpuguy83 commentedon Feb 3, 2015
@RoelVdP The build container is the same thing as a
docker run
container./etc/hosts is mounted as read-write, and I checked just to make sure.
RoelVdP commentedon Feb 3, 2015
@cpuguy83 A nice one-line workaround you found there, but it's not static;
$ cat Dockerfile
FROM busybox
RUN echo 8.8.8.8 foo > /etc/hosts; cat /etc/hosts
RUN cat /etc/hosts
$ sudo docker build .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM busybox
---> 4986bf8c1536
Step 1 : RUN echo 8.8.8.8 foo > /etc/hosts; cat /etc/hosts
---> Running in 22d95c996843
8.8.8.8 foo
---> 5df6fa4f3b7d
Removing intermediate container 22d95c996843
Step 2 : RUN cat /etc/hosts
---> Running in d989b8e95b85
172.17.0.33 7f674915980d
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
---> 1232cf428f6b
Removing intermediate container d989b8e95b85
Successfully built 1232cf428f6b
cpuguy83 commentedon Feb 3, 2015
Yep, you'd need to make your changes for each RUN command.
RoelVdP commentedon Feb 3, 2015
For anyone who's reading this; thanks to @cpuguy83 we now have the following workaround;
RUN echo ${IP} ${NAME} >> /etc/hosts; ${COMMAND}
The command HAS to be on the same line as the hosts addition (it will not be there the next RUN command), but at least this can be used for each command where needed. Definitely easier then the workaround at http://jasonincode.com/customizing-hosts-file-in-docker/
@cpuguy83 Thanks. While a nice workaround, it would still be great to have the --add-host solution mentioned earlier?
104 remaining items