|
| 1 | +--- |
| 2 | +title: Docker Deployment |
| 3 | +impact: HIGH |
| 4 | +impactDescription: Proper Docker deployment ensures NextDNS CLI runs efficiently with correct network configuration for host detection and client IP visibility |
| 5 | +type: capability |
| 6 | +tags: docker, container, DockerHub, host network, port mapping, deployment |
| 7 | +--- |
| 8 | + |
| 9 | +# Docker Deployment |
| 10 | + |
| 11 | +**Impact: HIGH** - Essential container deployment patterns for optimal DNS resolution and client tracking |
| 12 | + |
| 13 | +NextDNS CLI is available as pre-built Docker images on DockerHub (`nextdns/nextdns`), enabling containerized deployments across various platforms. The networking mode significantly affects functionality, particularly for host detection and client IP visibility. |
| 14 | + |
| 15 | +## Host Network Mode (Recommended) |
| 16 | + |
| 17 | +Using host network mode allows the NextDNS CLI container to see actual LAN IP addresses and enables host detection features: |
| 18 | + |
| 19 | +```bash |
| 20 | +docker run -d --network host --restart unless-stopped nextdns/nextdns run -listen=:53 -profile=abc123 |
| 21 | +``` |
| 22 | + |
| 23 | +### Why Host Network Mode? |
| 24 | + |
| 25 | +- **Real IP Visibility**: The CLI sees actual client IP addresses from your LAN instead of Docker's internal NAT IPs. |
| 26 | +- **Host Detection**: Automatic device identification works properly since the CLI can observe network traffic patterns. |
| 27 | +- **Performance**: Eliminates NAT overhead for DNS queries. |
| 28 | +- **Simplicity**: No port mapping required, direct access to port 53. |
| 29 | + |
| 30 | +### Important Considerations |
| 31 | + |
| 32 | +- Host network mode only works on Linux hosts. |
| 33 | +- The container shares the host's network stack directly. |
| 34 | +- Ensure no other service is listening on port 53 on the host. |
| 35 | + |
| 36 | +## Port Translation Mode |
| 37 | + |
| 38 | +When host network mode is not available or desired, use port mapping: |
| 39 | + |
| 40 | +```bash |
| 41 | +docker run -d -p 53:53/tcp -p 53:53/udp --restart unless-stopped nextdns/nextdns run -listen=:53 -profile=abc123 |
| 42 | +``` |
| 43 | + |
| 44 | +### Limitations |
| 45 | + |
| 46 | +- **NAT IP Addresses**: All clients appear as internal Docker NATed IP addresses (typically from the Docker bridge network). |
| 47 | +- **No Host Detection**: Device identification features will not work properly. |
| 48 | +- **Query Attribution**: All queries appear to come from the Docker container's IP rather than individual clients. |
| 49 | + |
| 50 | +### When to Use |
| 51 | + |
| 52 | +- On macOS or Windows Docker Desktop where host networking is not supported. |
| 53 | +- In environments where network isolation is required. |
| 54 | +- For testing or development purposes. |
| 55 | + |
| 56 | +## Persistence Configuration |
| 57 | + |
| 58 | +The `--restart unless-stopped` flag ensures the container automatically restarts on system boot and after Docker daemon restarts: |
| 59 | + |
| 60 | +```bash |
| 61 | +docker run -d \ |
| 62 | + --name nextdns \ |
| 63 | + --network host \ |
| 64 | + --restart unless-stopped \ |
| 65 | + nextdns/nextdns run -listen=:53 -profile=abc123 |
| 66 | +``` |
| 67 | + |
| 68 | +### Restart Policy Options |
| 69 | + |
| 70 | +- `unless-stopped`: Container restarts automatically unless explicitly stopped (recommended for production). |
| 71 | +- `always`: Container always restarts, even after manual stops (not recommended). |
| 72 | +- `on-failure`: Only restarts on non-zero exit codes. |
| 73 | +- `no`: No automatic restart (default, not recommended for DNS services). |
| 74 | + |
| 75 | +## Configuration File Persistence |
| 76 | + |
| 77 | +To persist configuration across container restarts, mount the configuration directory: |
| 78 | + |
| 79 | +```bash |
| 80 | +docker run -d \ |
| 81 | + --name nextdns \ |
| 82 | + --network host \ |
| 83 | + --restart unless-stopped \ |
| 84 | + -v /etc/nextdns:/etc/nextdns \ |
| 85 | + nextdns/nextdns run -listen=:53 -profile=abc123 |
| 86 | +``` |
| 87 | + |
| 88 | +This allows the CLI to store and read configuration from `/etc/nextdns` on the host system. |
| 89 | + |
| 90 | +## Best Practices |
| 91 | + |
| 92 | +- **Always Use Restart Policy**: DNS services must be highly available. Use `--restart unless-stopped` for production deployments. |
| 93 | +- **Prefer Host Network Mode**: On Linux systems, host network mode provides the best functionality and performance. |
| 94 | +- **Profile ID Management**: Store profile IDs securely, consider using Docker secrets or environment variables for sensitive configurations. |
| 95 | +- **Resource Limits**: In production, consider setting memory and CPU limits to prevent resource exhaustion. |
| 96 | +- **Logging**: Use Docker logging drivers to capture and rotate NextDNS CLI logs appropriately. |
| 97 | + |
| 98 | +## Container Management |
| 99 | + |
| 100 | +```bash |
| 101 | +# View container status |
| 102 | +docker ps -f name=nextdns |
| 103 | + |
| 104 | +# View logs |
| 105 | +docker logs nextdns |
| 106 | + |
| 107 | +# Stop container |
| 108 | +docker stop nextdns |
| 109 | + |
| 110 | +# Remove container |
| 111 | +docker rm nextdns |
| 112 | + |
| 113 | +# Pull latest image |
| 114 | +docker pull nextdns/nextdns:latest |
| 115 | +``` |
| 116 | + |
| 117 | +## Troubleshooting |
| 118 | + |
| 119 | +### Port Already in Use |
| 120 | + |
| 121 | +If port 53 is already in use: |
| 122 | + |
| 123 | +```bash |
| 124 | +# Check what's using port 53 |
| 125 | +sudo lsof -i :53 |
| 126 | +# or |
| 127 | +sudo netstat -tulpn | grep :53 |
| 128 | + |
| 129 | +# Common conflicts: systemd-resolved, dnsmasq |
| 130 | +# Disable systemd-resolved if needed |
| 131 | +sudo systemctl disable systemd-resolved |
| 132 | +sudo systemctl stop systemd-resolved |
| 133 | +``` |
| 134 | + |
| 135 | +### Container Not Starting |
| 136 | + |
| 137 | +Check logs for errors: |
| 138 | + |
| 139 | +```bash |
| 140 | +docker logs nextdns |
| 141 | +``` |
| 142 | + |
| 143 | +Common issues: |
| 144 | +- Invalid profile ID |
| 145 | +- Port conflicts |
| 146 | +- Network configuration errors |
| 147 | +- Insufficient permissions |
| 148 | + |
| 149 | +## Reference |
| 150 | + |
| 151 | +- [NextDNS CLI GitHub](https://github.com/nextdns/nextdns) |
| 152 | +- [NextDNS Docker Hub](https://hub.docker.com/r/nextdns/nextdns) |
| 153 | +- [Docker Networking Documentation](https://docs.docker.com/engine/network/) |
| 154 | +- [Docker Restart Policies](https://docs.docker.com/config/containers/start-containers-automatically/) |
0 commit comments