So I code my own custom dhcp server for specific job and I want to deploy it using docker. I need to expose it on port 67/udp and use network_mode host. I tried configuring my docker-compose like this.
version: '3'
services:
dhcp:
container_name: custom_dhcp_server
image: registry.patty.com/custom_dhcp_server:latest
restart: always
command: python3 -u src/dhcp_server.py
ports:
- "67:67/udp"
network_mode: "host"
but I just found that I can't expose port with network_mode host. So how can I deploy it using docker.
but I just found that I can't expose port with network_mode host.
While that's true, it's because it's unnecessary. When you're running in the host network namespace, you don't need to use port mapping because whatever port you listen on is a host port. As long as your custom DHCP server is listening for UDP traffic on port 67, you're all set.
If things don't appear to be working, there are a number of diagnostic steps you can try.
What happens if you run a non-custom dhcp server? dnsmasq is good for this because it's relatively simple to configure.
Add debugging code to your custom dhcp server. Is it receiving any requests?
Check your firewall; any chance you're blocking the dhcp requests?
Etc.