I’m trying to build bind9 with docker, using shared volume for zone files
I want to build bind9 with centos in docker. In Dockerfile i install bind, and during installation it creates /var/named with some files, but when i start the container using shared volume on /var/named, on which i have zone files, original files in /var/named are gone
FROM centos
RUN yum -y install bind -> after that, there are files in /var/named
but when i start the container using:
-v /path/to/zonefiles/folder:/var/named
container fails to start, because originally files in /var/named are gone
Any suggestion how to overcome this problem? maybe it possible to use shared volume during “docker build”?
2
Answers
I’m not familiar with Bind9, but the
-v /path/to/zonefiles/folder:/var/named
argument mounts a volume at /var/named in the container at runtime, in place of whatever may have been on the image. The only way you can have files in /var/named at runtime is if those same files happen to be in /path/to/zonefiles on your host at runtime.You should probably consider mounting the files to a different point than /var/named. So
-v /path/to/zonefiles/folder:/var/namedSomethingElse
.I assume you are trying to add the local files in
/path/to/zonefiles/folder
on your host to the ones generated bybind
in/var/named
. The only way that I can see how to do that is to combine the folders yourself.As you have seen, a volume mount will overlay the filesystem at the mount point. In order to achieve what you want, you must copy the files at the mount point before creating the new mount and combine them with your local files so that they still exist after the volume mount.
The following procedure should accomplish this:
Explanation:
I believe this will accomplish the desired behavior that you are looking for.