# docker-dnsd

> A local DNS server that replies with Docker container IP addresses for queries matching a container's network alias

Latest version **1.0.0** (published 2021-07-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install docker-dnsd
pnpm add docker-dnsd
yarn add docker-dnsd
bun add docker-dnsd
```

Provides the command `docker-dnsd`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-07-31 |
| First published | 2021-07-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ttoohey |

## Links

- npm: https://www.npmjs.com/package/docker-dnsd
- Homepage: https://github.com/ttoohey/docker-dnsd
- Issues: https://github.com/ttoohey/docker-dnsd/issues
- npm.io page: https://npm.io/package/docker-dnsd

## Dependencies (3)

- [dnsd](https://npm.io/package/dnsd.md) ^0.9.6
- [optionator](https://npm.io/package/optionator.md) ^0.9.1
- [harbor-master](https://npm.io/package/harbor-master.md) ^1.32.1

## Recent versions

- 1.0.0 (latest) — 2021-07-31

## README

# docker-dnsd: DNS server for Docker network aliases

A local DNS server that replies with IP addresses for queries matching a Docker
container's network alias.

## Why

We want to be able to access a container's service from the Docker host by using
a domain name to resolve the IP address of the container.

The alternatives are to map the service's ports to `localhost`, or to use
`docker container inspect` to discover the IP address assigned to each container.

## Usage

There are three steps:

1. install the `docker-dnsd` package from npm
2. configure the DNS resolver
3. setup to run as a daemon on boot

### Installation

```sh
sudo npm install docker-dnsd -g
```

Options:

```
--port Int       port number for the server to listen on - default: 20053
--host String    host or IP address for the server to listen on - default: localhost
--socket String  path to local Docker socket - default: /var/run/docker.sock
-h, --help       displays help
```

`docker-dnsd` is a DNS server that responds to DNS queries. It can be queried using
local DNS tools like `dig`

```sh
dig @localhost -p 20053 container-network-alias
```

It's more useful when used as a nameserver for a specific domain and added to the
host system's resolver. It's helpful to choose a domain name that won't conflict with
anything else on the host system (`docker.test` is recommended).
Containers will need to have a network alias within the domain.

### DNS resolver

Here we tell the OS DNS resolver to use `docker-dnsd` to resolve names matching the
`docker.test` domain.

#### Linux - dnsmasq

Add dnsmasq configuration

```
# /etc/dnsmasq.d/docker.test
server=/docker.test/127.0.0.1#20053
```

#### Mac - resolver

Add resolver configuration

```
# /etc/resolver/docker.test
nameserver 127.0.0.1
port 20053
```

### Start on boot

_so you never have to think about this again_

#### cross platform - pm2

Install `pm2` and run the [startup script](https://pm2.keymetrics.io/docs/usage/startup/)

```sh
sudo npm install pm2 -g
pm2 startup
```

Start `docker-dnsd` and save so it will be restored on boot

```sh
pm2 start docker-dnsd
pm2 save
```

### Docker configuration

Provide a network alias using the `.docker.test` domain name for any containers
you want to lookup the IP address by domain name on the host machine.

```yaml
# my-project/docker-compose.yml
services:
  service-a:
    networks:
      default:
        aliases:
          - service-a.my-project.docker.test
```

:tada:

## How it works

`docker-dnsd` uses the Docker daemon API via the local socket to access the
container details and monitor for containers being added or removed. It then
runs a tiny DNS server to respond with the IP address for any name that matches
a container's network alias.

---
_Source: https://npm.io/package/docker-dnsd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
