GithubHelp home page GithubHelp logo

phyber / docker-mdns Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 209 KB

Tool for publishing mDNS names via Avahi based on Docker labels

License: Apache License 2.0

Makefile 11.40% Dockerfile 1.00% Rust 87.60%
avahi docker mdns rust

docker-mdns's Introduction

Docker mDNS

Docker mDNS registers hostnames with Avahi based on labels given to a container. This allows each container to have a unique hostname.local assigned to it, which should help when reverse proxying from tools like Traefik or NGINX.

Minimum Supported Rust Version (MSRV)

The MSRV for this project is currently v1.75.0

Configuration

Docker mDNS takes a single command line argument which is the host interface that it should use to find addresses to announce. For example, if you launch it as docker-mdns eth0 and eth0 has the IP address 10.20.30.40 this will be the IP address used when when replying to mDNS queries.

Docker mDNS will attempt to find all IP (v4 and v6) addresses on an interface, as long as they aren't loopback addresses.

The rest of the Docker mDNS configuration is done through labels. The supported labels are:

Label Default Description
docker-mdns.enable false Enable mDNS for the container
docker-mdns.host None Hostname(s) to announce
docker-mdns.interface None Interface to get addresses from

The docker-mdns.host label can take a list of whitespace separated hostnames if you want multiple hostnames for a container.

Providing docker-mdns.interface will override which interface Docker mDNS uses when finding IP addresses to announce for the docker-mdns.host.

The following is an example of a docker-compose.yaml file to run Docker mDNS in a container:

---
version: "3.8"

services:
  mdns:
    container_name: "docker-mdns"
    image: "ghcr.io/phyber/docker-mdns:aarch64-latest"

    # We need to be able to see the real IP addresses on the host, so we need
    # host networking mode.
    network_mode: "host"

    # Set this to the name of the interface with the IP addresses you'd like to
    # announce for your hostnames.
    # Both IPv4 and IPv6 addresses will be used.
    command:
      - "eth0"

    # We need to be able to read docker.sock to watch for container events,
    # and we need to be able to write to the system d-bus socket to add
    # hostnames in Avahi
    volumes:
      - "/var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:rw"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

And the following would configure Traefik to present its dashboard on a configured mDNS hostname:

---
version: "3.8"

services:
  traefik:
    container_name: "traefik"
    image: "traefik:v2.8.1"
    restart: "unless-stopped"
    command:
      - "--entrypoints.web.address=:80"
      - "--providers.docker=true"
      - "--providers.docker.exposebydefault=false"
    labels:
      docker-mdns.enable: "true"
      docker-mdns.host: "traefik.local"
      traefik.enable: "true"
      traefik.http.routers.traefik.endpoints: "web"
      traefik.http.routers.traefik.rule: "Host(`traefik.local`)"
      traefik.http.services.traefik.loadbalancer.server.port: "8080"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

License

Licensed under either of

at your option.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.