Bootstrap FreeKB - DHCP - Install DHCPD on Docker
DHCP - Install DHCPD on Docker

Updated:   |  DHCP articles

A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).

 

The docker pull command can be used to pull down the latest dhcpd image.

~]# docker pull networkboot/dhcpd
Using default tag: latest
latest: Pulling from networkboot/dhcpd
171857c49d0f: Pull complete
419640447d26: Pull complete
61e52f862619: Pull complete
9743765a89f2: Pull complete
a6b215f926d1: Pull complete
Digest: sha256:cc08468fbecfbe18002450620ede54d2d33892524076ac53c34361210740bcf6
Status: Downloaded newer image for networkboot/dhcpd:latest
docker.io/networkboot/dhcpd:latest

 

Or you could create Dockerfile so that the Dockerfile contains something like this.

FROM dhcpd:latest

 

Then use the docker build command to create the image, running this command in the same directory as the Dockerfile.

docker build . --tag dhcpd:latest

 

The docker images command can be used to display the DHCPD image.

~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED         SIZE
networkboot/dhcpd   latest    b57b32205814   10 months ago   79.3MB

 

Create the dhcpd.conf file on the Docker server.

touch /usr/local/docker/dhcpd/dhcpd.conf

 

The dhcpd.conf file should at least have the following.

  • option routers should be the IP address of the router in your network
  • option domain-name-servers should be the IP addresses of the DNS name servers that will be assigned to your clients
  • Range is the range of IP addresses that can be leased by clients. In this example, IP addresses 192.168.0.1 through 192.168.0.99 cannot be leased, so that these IP addresses can be used as static IP addresses for servers and infrastructure devices.
subnet 192.168.0.0 netmask 255.255.255.0 {
  option routers                  192.168.0.1;
  option subnet-mask              255.255.255.0;
  option domain-name-servers      192.168.0.5, 192.168.0.6;
  default-lease-time              43200;
  max-lease-time                  86400;
  range                           192.168.0.100 192.168.0.254;
}

 

The following command can then be used to create and start the dhcpd container. Let's break down this command.

  • The docker run command is used to create and start the dhcpd container.
  • The --detach flag is used to run the container in the background.
  • The --volume option is used to mount the /usr/local/docker/dhcpd directory on the Docker server to the /data directory in the Docker container. The /usr/local/docker/dhcp directory on the Docker container has the dhcpd.conf file.
  • The --name option is used to name the container dhcpd.
  • The --network host option is used to so that the Docker server (not the container) network is used.
  • The --restart unless-stopped option is used so that the container is started if the Docker server is restarted
  • The networkboot/dhcpd image is used.
  • The eth0 option us used to use the eth0 network interface
docker run 
--detach
--volume /usr/local/docker/dhcpd:/data
--network host
--name dhcpd
--restart unless-stopped
networkboot/dhcpd
eth0

 

Use the docker container ls command to ensure the container is running.

~]# docker container ls -a
CONTAINER ID   IMAGE               COMMAND            CREATED       STATUS       NAMES
ba2fff144f7f   networkboot/dhcpd   "/entrypoint.sh"   3 hours ago   Up 3 hours   dhcpd

 

The docker logs command should return something like this.

~]# docker logs dhcpd
Internet Systems Consortium DHCP Server 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /data/dhcpd.conf
Database file: /data/dhcpd.leases
PID file: /var/run/dhcpd.pid
Wrote 0 leases to leases file.
Listening on LPF/eth0/00:0c:29:ad:31:5d/192.168.0.0/24
Sending on   LPF/eth0/00:0c:29:ad:31:5d/192.168.0.0/24
Sending on   Socket/fallback/fallback-net
Server starting service.

 

To confirm that the DHCPD service is working, the /data/dhcpd.leases file should have something like this.

~]# docker exec dhcpd cat /data/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.3.5

# authoring-byte-order entry is generated, DO NOT DELETE
authoring-byte-order little-endian;

lease 192.168.0.100 {
  starts 1 2021/09/06 21:37:20;
  ends 1 2021/09/06 21:39:20;
  cltt 1 2021/09/06 21:37:20;
  binding state free;
  hardware ethernet 08:78:08:3c:81:b8;
  uid "\001\010x\010<\201\270";
  set vendor-class-identifier = "android-dhcp-9";
  client-hostname "Galaxy-Tab-A-2017";
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


October 31 2024 by Ana
Hi team, I follow your process, but my container doesn´t up. Look, I have the image [xr-vm_nodehost_CPU0:/]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE networkboot/dhcpd latest e25c872f0fca 2 years ago 139MB [xr-vm_nodehost_CPU0:/]$ I created the .conf file [xr-vm_nodehost_CPU0:/usr/local/docker/dhcpd]$ ls dhcpd.conf dhcpd.conf~ [xr-vm_nodehost_CPU0:/usr/local/docker/dhcpd]$ this is the information in .conf file [xr-vm_nodehost_CPU0:/usr/local/docker/dhcpd]$ vim dhcpd.conf subnet 192.168.0.0 netmask 255.255.255.0 { option routers 192.168.0.1; option subnet-mask 255.255.255.0; option domain-name-servers 192.168.0.5, 192.168.0.6; default-lease-time 43200; max-lease-time 86400; range 192.168.0.100 192.168.0.254; } ~ ~ But when I run the container, it doesn´t work. [xr-vm_nodehost_CPU0:/]$ docker run "docker run" requires at least 1 argument. See 'docker run --help'. Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container [xr-vm_nodehost_CPU0:/]$ --detach --volume /usr/local/docker/dhcpd:/data --network host sh: --detach: command not found --name dhcpd [xr-vm_nodehost_CPU0:/]$ --volume /usr/local/docker/dhcpd:/data dhcpd eth0sh: --volume: command not found [xr-vm_nodehost_CPU0:/]$ --network host sh: --network: command not found [xr-vm_nodehost_CPU0:/]$ --name dhcpd sh: --name: command not found [xr-vm_nodehost_CPU0:/]$ --restart unless-stopped sh: --restart: command not found [xr-vm_nodehost_CPU0:/]$ dhcpd Internet Systems Consortium DHCP Server 4.4.2 Copyright 2004-2020 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Config file: /etc/dhcp/dhcpd.conf Database file: /var/lib/dhcp/dhcpd.leases PID file: /var/run/dhcpd.pid Wrote 0 leases to leases file. No subnet declaration for BE1002.20 (no IPv4 addresses). ** Ignoring requests on BE1002.20. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface BE1002.20 is attached. ** No subnet declaration for Lo116 (116.16.16.16). ** Ignoring requests on Lo116. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Lo116 is attached. ** No subnet declaration for Hu0_0_0_2 (no IPv4 addresses). ** Ignoring requests on Hu0_0_0_2. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Hu0_0_0_2 is attached. ** No subnet declaration for Hu0_0_0_4 (173.1.1.14). ** Ignoring requests on Hu0_0_0_4. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Hu0_0_0_4 is attached. ** No subnet declaration for Hu0_0_0_5 (173.1.1.17). ** Ignoring requests on Hu0_0_0_5. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Hu0_0_0_5 is attached. ** No subnet declaration for Hu0_0_0_10 (no IPv4 addresses). ** Ignoring requests on Hu0_0_0_10. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Hu0_0_0_10 is attached. ** No subnet declaration for Hu0_0_0_23 (no IPv4 addresses). ** Ignoring requests on Hu0_0_0_23. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Hu0_0_0_23 is attached. ** No subnet declaration for Hu0_0_0_0 (no IPv4 addresses). ** Ignoring requests on Hu0_0_0_0. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Hu0_0_0_0 is attached. ** No subnet declaration for BE1002 (no IPv4 addresses). ** Ignoring requests on BE1002. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface BE1002 is attached. ** No subnet declaration for Lo5 (192.168.1.2). ** Ignoring requests on Lo5. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Lo5 is attached. ** No subnet declaration for Lo0 (117.96.88.98). ** Ignoring requests on Lo0. If this is not what you want, please write a subnet declaration in your dhcpd.conf file for the network segment to which interface Lo0 is attached. ** Not configured to listen on any interfaces! If you think you have received this message due to a bug rather than a configuration issue please read the section on submitting bugs on either our web page at www.isc.org or in the README file before submitting a bug. These pages explain the proper process and the information we find helpful for debugging. exiting. [xr-vm_nodehost_CPU0:/]$ eth0 sh: eth0: command not found [xr-vm_nodehost_CPU0:/]$ Can you help me to up the DHCP container, please?

Add a Comment


Please enter 0d5d64 in the box below so that we can be sure you are a human.