Code Monkey home page Code Monkey logo

docker-dnsmasq's Introduction

Docker DNSMASQ

Docker Pulls

Dnsmasq is a lightweight, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS. The DHCP server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP/TFTP for network booting of diskless machines.

Example in a docker-compose

Here is a docker-compose.yml file that run a local dns server using this image. You can adapt it for your own needs as you wish.

version: '2'
services:
  dns:
    restart: always
    image: strm/dnsmasq
    volumes:
      - ./dnsmasq.conf:/etc/dnsmasq.conf
    ports:
      - "53:53/udp"
    cap_add:
      - NET_ADMIN

Deploy with ansible demo playbook

Is possible to deploy with ansible using this role to create a complete Debian buster setup with docker and everything else that you may need.

- hosts: all
  vars:
    hostname: "my_dns_server"
    domain: "strm.sh"
    network:
      ip: "192.168.0.9"
      gateway: "192.168.0.1"
      dns: "8.8.8.8"
    github_user: opsxcq
  tasks:
  - name: "Network | Create DNS container"
    copy:
      dest: /config/dnsmasq.conf
      content: |
        #log all dns queries
        log-queries
        #dont use hosts nameservers
        no-resolv
        #use google as default nameservers
        server=8.8.4.4
        server=8.8.8.8
        #explicitly define host-ip mappings
        address=/server/10.1.1.2
        address=/server/10.1.1.2

  - name: "Network | Create DNS container"
    docker_container:
      name: dns
      image: strm/dnsmasq
      restart_policy: unless-stopped
      ports:
        - "53:53/tcp"
        - "53:53/udp"
      entrypoint:
        - dnsmasq
        - "-d"
      volumes:
        - /config/dnsmasq.conf:/etc/dnsmasq.conf
      capabilities:
      - NET_ADMIN
  roles:
    - opsxcq.linux_server

Configuration Example

To be able to run the above example, you will need a configuration file. This is a very basic example that has two hosts, but it serve our purpose.

#log all dns queries
log-queries
#dont use hosts nameservers
no-resolv
#use google as default nameservers
server=8.8.4.4
server=8.8.8.8
#explicitly define host-ip mappings
address=/router/10.1.1.1
address=/server/10.1.1.2

docker-dnsmasq's People

Contributors

opsxcq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

docker-dnsmasq's Issues

Problem mounting the config

I've got the following foler:

$ lh
total 8.0K
drwxr-xr-x 2 root  root  4.0K Aug  9 11:34 dnsmasq.conf
-rw-rw-r-- 1 parsa parsa  223 Aug  9 11:19 docker-compose.yml

Got the following on the docker-compose.yml:

version: '2'
services:
  dns:
    restart: always
    image: strm/dnsmasq
    volumes:
      - ./dnsmasq.conf:/etc/dnsmasq.conf
    ports:
      - "53:53/udp"
    cap_add:
      - NET_ADMIN
    container_name: dnsmasq

Which is exactly as what is mentioned by the readme.md.
But I get following on running the container:

Starting dnsmasq ... error

ERROR: for dnsmasq  Cannot start service dns: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/parsa/docker-compose-files/dnsmasq/dnsmasq.conf" to rootfs at "/etc/dnsmasq.conf": mount /home/parsa/docker-compose-files/dnsmasq/dnsmasq.conf:/etc/dnsmasq.conf (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

ERROR: for dns  Cannot start service dns: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/parsa/docker-compose-files/dnsmasq/dnsmasq.conf" to rootfs at "/etc/dnsmasq.conf": mount /home/parsa/docker-compose-files/dnsmasq/dnsmasq.conf:/etc/dnsmasq.conf (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.

What's wrong?

will it work for windows?

Hi, I was wondering if you know an approach of using your image in order to make it work with windows, on macOS it works perfectly but as you know it requires a resolver setup and that is not quite easy to achieve in windows.

I'm trying to setup a DNS for local dev that works in macOS and Windows. I need *.example.com to resolve to localhost for local development.

Any help or tip to know in what direction should I take?

Can't get logging to work

Hello! Thank you for this docker image ๐Ÿ™‚. I haven't been able to get logging to work, except if I use the -d flag, which I don't want to use in production. The -q flag should log all queries, but I only see logs with the -d flag. Any idea? I'm running the container with:

docker run -it -p 53:53/udp -p 53:53/tcp -v $(pwd)/dnsmasq.conf:/etc/dnsmasq.conf --cap-add=NET_ADMIN strm/dnsmasq -q

With very simple dnsmasq.conf:

address=/router/10.1.1.1

When I run the container and dig router I get a record for 10.1.1.1 in return, so the container is running fine but I'm just not seeing logs. Thanks for the help!

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.