Mathis
Mathis

Reputation: 67

I try to build a docker container that include externals files

I try to create a docker container with bind9 on it and I want to add my db.personal-domain.com file but when I run docker build and then docker run -tdp 53:53 -v config:/etc/bind <image id> the container doesn't have my db.personal-domain.com file. How to fix that ? Thanks !

tree structure

-DNS
--Dockerfile
--config
---db.personal-domain.com

Dockerfile

FROM ubuntu:20.04

RUN apt-get update
RUN apt-get install -y bind9
RUN apt-get install -y bind9utils

WORKDIR /etc/bind
VOLUME ["/etc/bind"]

COPY config/db.personal-domain.com /etc/bind/db.personal-domain.com


EXPOSE 53/tcp

CMD ["/usr/sbin/named", "-g", "-c", "/etc/bind/named.conf", "-u", "bind"]

Upvotes: 0

Views: 399

Answers (2)

David Maze
David Maze

Reputation: 159830

There is a syntax issue in your docker run -v option. If you use docker run -v name:/container/path (even if name matches a local file or directory) it mounts a named volume over your configuration directory. You want the host content, and you need -v /absolute/host/path:/container/path syntax (the host path must start with /). So (on Linux/MacOS):

docker run -d -p 53:53 \
  -v "$PWD:config:/etc/bind" \
  my/bind-image

In your image you're trying to COPY in the config file. This could work also; but it's being hidden by the volume mount, and also rendered ineffective by the VOLUME statement. (The most obvious effect of VOLUME is to prevent subsequent changes to the named directory; it's not required to mount a volume later.)

If you delete the VOLUME line from the Dockerfile, it should also work to run the container without the -v option at all. (But if you'll have different DNS configuration on different setups, this probably isn't what you want.)

Upvotes: 1

BMitch
BMitch

Reputation: 264986

-v config:/etc/bind

That syntax creates a named volume, called config. It looks like you wanted a host volume pointing to a path in your current directory, and for that you need to include a fully qualified path with the leading slash, e.g. using $(pwd) to generate the path:

-v "$(pwd)/config:/etc/bind"

Upvotes: 1

Related Questions