|
| 1 | ++++ |
| 2 | +title = "docker" |
| 3 | +description = "*example* - enables reading zone data from the Docker Daemon" |
| 4 | +weight = 10 |
| 5 | +tags = [ "plugin" , "docker" ] |
| 6 | +categories = [ "plugin", "external" ] |
| 7 | +date = "2025-12-18T18:39:00+04:00" |
| 8 | +repo = "https://github.com/dokku/coredns-docker" |
| 9 | +home = "https://github.com/dokku/coredns-docker/blob/master/README.md" |
| 10 | ++++ |
| 11 | + |
| 12 | +## Description |
| 13 | + |
| 14 | +The docker plugin serves DNS records for containers running on the local Docker daemon. It follows the Docker event stream, picking up changes whenever something happens to a container - whether it gets created, started, deleted, or restarted. |
| 15 | + |
| 16 | +The plugin resolves container names, network aliases, DNS names, and SRV records to their respective container IP addresses within a specified network. |
| 17 | + |
| 18 | +SRV records can be defined using container labels with the prefix `[LABEL_PREFIX].srv.`, followed by the protocol and service name. For example, with the default prefix, a label `com.dokku.coredns-docker.srv._tcp._http=80` will create an SRV record for `_http._tcp.container-name.domain` pointing to the container's IP on port 80. |
| 19 | + |
| 20 | +If no labels with the specified prefix are found, the plugin falls back to using the container's exposed ports (`NetworkSettings.Ports`). |
| 21 | + |
| 22 | +- For a port mapping like `80/tcp`, it generates an SRV record for `_tcp._tcp.container-name.domain`. |
| 23 | +- For a port mapping without a protocol like `80`, it generates SRV records for both `_tcp._tcp` and `_udp._udp`. |
| 24 | + |
| 25 | +## Compilation |
| 26 | + |
| 27 | +It will require you to use `go get` or as a dependency on [plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg). |
| 28 | + |
| 29 | +A simple way to consume this plugin, is by adding the following on [plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg), and recompile it as [detailed on coredns.io](https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-compile-time-configuration-file). |
| 30 | + |
| 31 | +```text |
| 32 | +docker:github.com/dokku/coredns-docker |
| 33 | +``` |
| 34 | + |
| 35 | +After this you can compile coredns by running: |
| 36 | + |
| 37 | +```bash |
| 38 | +make |
| 39 | +``` |
| 40 | + |
| 41 | +## Syntax |
| 42 | + |
| 43 | +```text |
| 44 | +docker [DOMAIN] { |
| 45 | + ttl DURATION |
| 46 | + label_prefix PREFIX |
| 47 | + max_backoff DURATION |
| 48 | + networks NETWORK... |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +- `DOMAIN` is the domain for which the plugin will respond. Defaults to `docker.`. |
| 53 | + |
| 54 | +- `ttl` allows you to set a custom TTL for responses. **DURATION** defaults to `30 seconds`. The minimum TTL allowed is `0` seconds, and the maximum is capped at `3600` seconds. Setting TTL to 0 will prevent records from being cached. The unit for the value is seconds. |
| 55 | + |
| 56 | +- `label_prefix` allows you to set a custom prefix for SRV record labels. **PREFIX** defaults to `com.dokku.coredns-docker`. |
| 57 | + |
| 58 | +- `max_backoff` allows you to set a maximum backoff duration for the Docker event loop reconnection logic. **DURATION** defaults to `60s`. |
| 59 | + |
| 60 | +- `networks` allows you to specify a list of Docker networks to monitor. If specified, containers not on one of these networks will be ignored. |
| 61 | + |
| 62 | +## Metrics |
| 63 | + |
| 64 | +If monitoring is enabled (via the *prometheus* directive) the following metric is exported: |
| 65 | + |
| 66 | +- `coredns_docker_success_requests_total{server}` - Counter of DNS requests handled successfully. |
| 67 | +- `coredns_docker_failed_requests_total{server}` - Counter of DNS requests failed. |
| 68 | + |
| 69 | +The `server` label indicated which server handled the request. |
| 70 | + |
| 71 | +## Ready |
| 72 | + |
| 73 | +This plugin reports readiness to the ready plugin. It will be ready only when it has successfully connected to the Docker daemon. |
| 74 | + |
| 75 | +## Examples |
| 76 | + |
| 77 | +Enable docker with and resolve all containers with `.docker.` as the suffix. |
| 78 | + |
| 79 | +```text |
| 80 | +docker:1053 { |
| 81 | + docker docker. |
| 82 | + cache 30 |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +You can see the [Corefile.example](./Corefile.example) for a full Corefile example. |
| 87 | + |
| 88 | +## Usage Example |
| 89 | + |
| 90 | +### A record |
| 91 | + |
| 92 | +```shell |
| 93 | +dig web.docker @127.0.0.1 -p 1053 |
| 94 | + |
| 95 | +; <<>> DiG 9.18.1-1ubuntu1.2-Ubuntu <<>> web.docker @127.0.0.1 -p 1053 |
| 96 | +;; global options: +cmd |
| 97 | +;; Got answer: |
| 98 | +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54986 |
| 99 | +;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 |
| 100 | +
|
| 101 | +;; QUESTION SECTION: |
| 102 | +;web.docker. IN A |
| 103 | +
|
| 104 | +;; ANSWER SECTION: |
| 105 | +web.docker. 30 IN A 172.17.0.2 |
| 106 | +
|
| 107 | +;; Query time: 4 msec |
| 108 | +;; SERVER: 127.0.0.1#1053(127.0.0.1) (UDP) |
| 109 | +``` |
| 110 | +
|
| 111 | +### SRV record |
| 112 | +
|
| 113 | +```shell |
| 114 | +dig _http._tcp.web.docker @127.0.0.1 -p 1053 SRV |
| 115 | +
|
| 116 | +; <<>> DiG 9.18.1-1ubuntu1.2-Ubuntu <<>> _http._tcp.web.docker @127.0.0.1 -p 1053 SRV |
| 117 | +;; global options: +cmd |
| 118 | +;; Got answer: |
| 119 | +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49945 |
| 120 | +;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 |
| 121 | +
|
| 122 | +;; QUESTION SECTION: |
| 123 | +;_http._tcp.web.docker. IN SRV |
| 124 | +
|
| 125 | +;; ANSWER SECTION: |
| 126 | +_http._tcp.web.docker. 30 IN SRV 10 10 80 web.docker. |
| 127 | +
|
| 128 | +;; Query time: 0 msec |
| 129 | +;; SERVER: 127.0.0.1#1053(127.0.0.1) (UDP) |
| 130 | +``` |
0 commit comments