I want to add a domain entry to /etc/resolv.conf
of my docker container.
Here is my dockerFile
FROM tomcat:8.0.20-jre7
VOLUME /tmp
#RUN sed -i "s|search local|domain com.example.com|g;" /etc/resolv.conf
RUN echo "domain com.example.com" >> /etc/resolv.conf
# Expose ports.
EXPOSE 8080
I tried both echo
and sed
.
with sed
, I get error during build.
sed: cannot rename /etc/sed6LcoES: Device or resource busy
but with echo
container build and run successfully.
however, when I get into container, I do not see my domain added in /etc/resolv.conf
.
why is it not working?
NOTE: I have got dns-search
working by passing during run argument
docker run -p 8080:8080 --dns-search=com.example.com -d --name myawesome my/myawesome:latest
but I am interested in getting dockerFile working.
This is by design. /etc/resolv.conf
is used by docker engine to handle service discovery. Documentation states the following:
How can Docker supply each container with a hostname and DNS configuration, without having to build a custom image with the hostname written inside? Its trick is to overlay three crucial /etc files inside the container with virtual files where it can write fresh information … This arrangement allows Docker to do clever things like keep resolv.conf up to date across all containers when the host machine receives new configuration over DHCP later. The exact details of how Docker maintains these files inside the container can change from one Docker version to the next, so you should leave the files themselves alone and use the following Docker options instead.
If you want to override/reconfigure some dns settings, use --dns
parameters during container starting. See more details: