docker-dns

command module
v1.1.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 10 Imported by: 0

README

Docker DNS Resolver

Tests Release Go Report Card License Go Reference

Logo

A lightweight DNS server that resolves Docker container names to their IP addresses, enabling seamless networking between containers and the host.

Features

  • Automatic DNS Resolution: Resolve Docker container names with a custom TLD to their respective IP addresses.
  • Caching Mechanism: Configurable TTL for DNS cache entries to improve performance.
  • Simple Configuration: Minimal setup with command-line options or a configuration file.
  • Debian Package: Easy-to-install .deb package for seamless integration.
  • Fallback DNS: Forwards non-Docker queries to configurable DNS servers.
  • Lightweight and Fast: Built with Go for high performance.

Installation

Download and Install the Debian Package
  1. Download the .deb Package:

    • Go to the Releases page.
    • Find the release matching your desired version (e.g., v1.1.0).
    • Download the .deb file:
      wget https://github.com/MedUnes/docker-dns/releases/download/v(version)/docker-dns-(version)_amd64.deb
      
  2. Install the Package:

    sudo dpkg -i docker-dns-(version)_amd64.deb
    
  3. Check the Service Status:

    • Ensure the service is running:
      systemctl status docker-dns
      
  4. Edit the Configuration (Optional):

    • The configuration file is located at /etc/docker-dns/docker-dns.conf.
    • Example:
      # Docker DNS Configuration
      PORT=5335
      TTL=300
      TLD=docker
      DEFAULT_RESOLVER=8.8.8.8,1.1.1.1,8.8.4.4
      
    • After making changes, restart the service:
      sudo systemctl restart docker-dns
      

Usage

Resolving Docker Container Names
  1. Test the Main Scenario: Assuming a container named mycontainer is running, resolve its IP:

    dig mycontainer.docker @127.0.0.1 -p 5335
    
  2. Test the Fallback DNS: Verify non-Docker queries are forwarded to the fallback DNS:

    dig google.com @127.0.0.1 -p 5335
    

Configuration

The application uses an INI-style configuration file located at /etc/docker-dns/docker-dns.conf. Below is an explanation of the configurable options:

  • PORT: The port number the DNS server listens on (default: 5335).
  • TTL: The time-to-live (in seconds) for cached DNS records (default: 300).
  • TLD: The top-level domain for resolving container names (default: docker).
  • DEFAULT_RESOLVER: A comma-separated list of fallback DNS servers (default: 8.8.8.8,1.1.1.1,8.8.4.4).
Restarting the Service After Changes

If you edit the configuration file, restart the service to apply changes:

sudo systemctl restart docker-dns

Important Notes

  • Default Resolver Integration: While Docker DNS runs on a custom port (not 53), it is possible to use tools like dig to test queries. However, making Docker DNS the system-wide default resolver requires additional configuration or hacks.
  • Systemd-Resolved Compatibility: Direct integration with systemd-resolved is non-trivial and not recommended without advanced setup.

Build from Source

For developers, you can build the application from source:

  1. Clone the repository:

    git clone https://github.com/medunes/docker-dns.git
    cd docker-dns
    
  2. Build the binary:

    go build -o docker-dns main.go
    
  3. Run the application:

    ./docker-dns
    

Contributing

Contributions are welcome!

  1. Fork the repository.
  2. Create a feature branch:
    git checkout -b feature/YourFeature
    
  3. Commit your changes:
    git commit -am 'Add YourFeature'
    
  4. Push to the branch:
    git push origin feature/YourFeature
    
  5. Open a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Empower your Docker networking with easy-to-use DNS resolution!

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL