Dockerfile will build an image with latest cobbler from source code, atftp server isc dhcpd server and apache2 all managed by supervisord.
Cobbler container runs in unprivileged mode, to be able to deliver dhcp broadcast to dhcp server in container we use dhcp-helper which will relay messages to either network device or dhcp server ip.
- If you are using
docker run
$ sudo vi /etc/default/dhcp-helper
DHCPHELPER_OPTS="-b docker0 -i ens3"
- when usign docker-compose
$ sudo vi /etc/default/dhcp-helper
DHCPHELPER_OPTS="-i ens3 -s 172.16.238.10"
- start dhcp-helper
$ sudo systemctl start dhcp-helper.service
Below script will download Bionic and Xenial iso.
$ ./download-iso-and-mount.sh
$ docker run -dt -v /mnt/:/mnt -p 80:80/tcp -p 69:69/udp --name cobbler urosorozel/cobbler:latest
$ docker-compose up --build -d
Run script against container
docker exec -it cobbler /bin/bash -c "$(<import-iso.sh)"
$ sudo modprobe ip_conntrack_tftp ip_nat_tftp
$ sudo iptables -t raw -A PREROUTING -p udp --dport 69 -j CT --helper tftp
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce qemu-kvm virtinst libvirt-bin python3-pip
For Xenial
$ sudo usermod -aG docker,libvirtd ubuntu
or Bionic
$ sudo usermod -aG docker,libvirt ubuntu
logout and login to take an affect
$ sudo su - $USER
- update subnet details if required
$ echo "<network>
<name>cobbler</name>
<dns enable="no"/>
<forward mode='nat'/>
<bridge name='cobbler' stp='on' delay='0'/>
<ip address='192.168.10.1' netmask='255.255.255.0'></ip>
</network>" | virsh net-define /dev/stdin
- start cobbler libvirt network
$ sudo virsh start cobbler
- When testing in VM we want to relay all DHCP requests from cobbler bridge to container subnet
$ sudo vi /etc/default/dhcp-helper
DHCPHELPER_OPTS="-i cobbler -s 172.16.238.10"
- start dhcp-helper
$ sudo systemctl restart dhcp-helper.service
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ git clone https://github.com/urosorozel/docker-cobbler.git
- Update variable according to you environment
# Cobbler server IP/hostname
COBBLER_SERVER_HOST_IP=192.168.122.91
# TFTP server
COBBLER_NEXT_SERVER_HOST_IP=192.168.122.91
# SSH public key
COBBLER_PUBLIC_SSH_KEY=
# Dhcp settings
COBBLER_SUBNET=192.168.10.0
COBBLER_NETMASK=255.255.255.0
COBBLER_ROUTERS=192.168.10.1
COBBLER_NAMESERVERS=8.8.8.8,1.1.1.1
COBBLER_DHCP_RANGE=192.168.10.50 192.168.10.100
# Proxy
COBBLER_PROXY_URL_EXT=
COBBLER_PROXY_URL_INT=
$ docker-compose up --build -d
Below script will download Bionic and Xenial iso.
$ ./download-iso-and-mount.sh
Run script against container
docker exec -it cobbler /bin/bash -c "$(<import-iso.sh)"
$ virt-install --connect qemu:///system \
--name demo \
--vcpu 2 \
--memory 2048 \
--disk size=10 \
--pxe \
--network network=cobbler,mac=0c:c4:7a:bb:ff:f1 \
--virt-type qemu \
--console pty,target_type=serial \
--graphics vnc,listen=0.0.0.0 \
--os-variant ubuntu18.04