en:ressources:articles:coredns
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | en:ressources:articles:coredns [2024/07/19 11:32] (current) – created admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== CoreDNS server inside a Docker container ====== | ||
+ | |||
+ | This howto describes how to run CoreDNS in a Docker container. It assumes a running docker setup. | ||
+ | |||
+ | ===== Fetch the container ===== | ||
+ | |||
+ | CoreDNS maintains a docker container at https:// | ||
+ | |||
+ | < | ||
+ | # docker pull coredns/ | ||
+ | Using default tag: latest | ||
+ | latest: Pulling from coredns/ | ||
+ | Digest: sha256: | ||
+ | Status: Image is up to date for coredns/ | ||
+ | docker.io/ | ||
+ | </ | ||
+ | |||
+ | ===== Create local configurations ===== | ||
+ | |||
+ | Configurations need to live outside the container and be mounted as a volume. We create a folder in / | ||
+ | |||
+ | The first configuration file declares a zone with the location of a database file. The second configuration file declares DNS records in a zone file. | ||
+ | |||
+ | < | ||
+ | # mkdir / | ||
+ | </ | ||
+ | < | ||
+ | # cat / | ||
+ | necto.org: | ||
+ | file / | ||
+ | log | ||
+ | errors | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The database file uses the standard Bind syntax. See [[https:// | ||
+ | |||
+ | Note that the serial *must* store in a 32 bits integer so keep it at 10 digits for simplicity. | ||
+ | |||
+ | < | ||
+ | # cat / | ||
+ | necto.org. IN SOA ns1.necto.org. administrator.necto.org. 2024071901 7200 3600 1209600 3600 | ||
+ | legolas.necto.org. IN A 75.67.215.94 | ||
+ | ns1.necto.org. IN CNAME legolas.necto.org. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Start the container ===== | ||
+ | |||
+ | The docker run command mounts the folder from the host into the container and sets the configuration flag to point to the Corefile file inside the container. We also forward UDP 53 to answer queries. | ||
+ | < | ||
+ | # docker run -d --name coredns --restart=always --volume=/ | ||
+ | </ | ||
+ | |||
+ | **docker ps**, **docker logs** and **docker inspect** can be used to evaluate the state of the container. | ||
+ | |||
+ | < | ||
+ | # docker ps | ||
+ | CONTAINER ID | ||
+ | 330c19f5b978 | ||
+ | |||
+ | # docker logs 330c19f5b978 | ||
+ | necto.org.: | ||
+ | CoreDNS-1.11.1 | ||
+ | linux/ | ||
+ | [INFO] 172.17.0.1: | ||
+ | [INFO] 199.47.252.56: | ||
+ | |||
+ | # docker inspect 330c19f5b978 | ||
+ | [ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | ===== Run the container as a systemd service ===== | ||
+ | |||
+ | To run the container as a systemd service, create the following service file under **/ | ||
+ | < | ||
+ | # cat / | ||
+ | [Unit] | ||
+ | Description=CoreDNS Container | ||
+ | After=docker.service | ||
+ | Requires=docker.service | ||
+ | |||
+ | [Service] | ||
+ | TimeoutStartSec=0 | ||
+ | Restart=always | ||
+ | ExecStartPre=-/ | ||
+ | ExecStartPre=-/ | ||
+ | ExecStartPre=/ | ||
+ | ExecStart=/ | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=multi-user.target | ||
+ | </ | ||
+ | And run it with the following command: | ||
+ | < | ||
+ | # systemctl start docker.coredns | ||
+ | |||
+ | # systemctl|grep coredns | ||
+ | docker.coredns.service | ||
+ | </ | ||
+ | |||
+ | Use **systemctl enable docker.coredns** to run it at startup. |
en/ressources/articles/coredns.txt · Last modified: 2024/07/19 11:32 by admin