skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. I assume you are trying to add the local files in /path/to/zonefiles/folder on your host to the ones generated by bind 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:

    docker build -t bind .
    docker run -d --name bind bind
    docker cp bind:/var/named /path/to/zonefiles/folder
    docker stop bind && docker rm bind
    docker run -d --name bind -v /path/to/zonefiles/folder:/var/named bind
    

    Explanation:

    1. The 1st line will build your image
    2. The 2nd line will run a container so that you can copy files from it
    3. The 3rd line will copy the generated files to your hosts folder
    4. The 4th line will stop and remove the container
    5. The 5th line runs your container with the combined config file folder

    I believe this will accomplish the desired behavior that you are looking for.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search