Skip to content

theonlysinjin/docker-pihole-dns-shim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-pihole-dns-shim

Synchronise records founds through docker labels with pihole's custom dns and cname records.

How to get started

Find your secret pihole token

  • Navigate to the api tab in your pihole settings
  • Click the Show API token button
  • Copy the Raw API Token
  • Use this as PIHOLE_TOKEN

Run

cli

docker run \
  -l "pihole.custom-record=[[\"pihole-dns-shim.lan\", \"127.0.0.1\"]]" \
  -e PIHOLE_TOKEN="" \
  -e PIHOLE_API="http://pi.hole:8080/admin/api.php" \
  -e STATE_FILE="/state/pihole.state" \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  theonlysinjin/docker-pihole-dns-shim

docker-compose.yml

services:
  pihole-dns-shim:
    container_name: "pihole-dns-shim"
    image: theonlysinjin/docker-pihole-dns-shim
    restart: unless-stopped
    labels:
      - pihole.custom-record=[["pihole-dns-shim.lan", "127.0.0.1"]]
    environment:
      PIHOLE_TOKEN: "${PIHOLE_TOKEN}"
      PIHOLE_API: "${PIHOLE_API}"
      # LOGGING_LEVEL: "DEBUG"
      # STATE_FILE: "/state/pihole.state"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

Label

Add records to pihole by labelling your docker containers, you can add as many labels(records) to individual containers as you need.
An example of the (json-encoded) label is as follows:

pihole.custom-record:
  - ["pihole-dns-shim.lan", "127.0.0.1"]
  - ["pihole-dns-shim.lan", "www.google.com"]

as a docker label:

"pihole.custom-record=[[\"pihole-dns-shim.lan\", \"127.0.0.1\"], [\"pihole-dns-shim.lan\", \"www.google.com\"]]"

Development

Debug

You can turn on extra logging by setting the log level to DEBUG,
Set an env variable in the container with LOGGING_LEVEL="DEBUG"

API Endpoints

Make a GET request to the following endpoints.
Replace the parts of the url that are in uppercase.

Manage A Records

Add new DNS record
http://pi.hole:8080/admin/api.php?customdns&action=add&ip=IPADDRESS&domain=DOMAIN&auth=XXX

Delete existing DNS record
http://pi.hole:8080/admin/api.php?customdns&action=delete&ip=IPADDRESS&domain=DOMAIN&auth=XXX

List existing DNS records
http://pi.hole:8080/admin/api.php?customdns&action=get&auth=XXX

Manage CNAME Records

Add new CNAME record
http://pi.hole:8080/admin/api.php?customcname&action=add&domain=DOMAIN&target=TARGET&auth=XXX

Delete existing CNAME record
http://pi.hole:8080/admin/api.php?customcname&action=delete&domain=DOMAIN&target=TARGET&auth=XXX

List existing CNAME records
http://pi.hole:8080/admin/api.php?customcname&action=get&auth=XXX

About

Synchronise records founds through docker labels with pihole's custom dns and cname records.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published