From e552b5657245f013621a19aa8e6953504bc8da03 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Wed, 16 Dec 2015 16:58:18 -0800 Subject: [PATCH] pixiecore: Add dhcp Dockerfile to simplify trying Pixiecore --- README.md | 40 +++++++++++++++-------------------- dockerfiles/dhcp/Dockerfile | 6 ++++++ dockerfiles/dhcp/docker-build | 5 +++++ dockerfiles/dhcp/docker-run | 3 +++ scripts/pixiecore | 6 +----- 5 files changed, 32 insertions(+), 28 deletions(-) create mode 100644 dockerfiles/dhcp/Dockerfile create mode 100755 dockerfiles/dhcp/docker-build create mode 100755 dockerfiles/dhcp/docker-run diff --git a/README.md b/README.md index 0e67e412..f356b9f9 100644 --- a/README.md +++ b/README.md @@ -117,15 +117,15 @@ Configure your iPXE server to chainload the `bootcfg` iPXE boot script hosted at #### docker0 -If you're running `bootcfg` on Docker an easy way to try PXE/iPXE booting is by running the included `ipxe` container on the same Docker bridge. +Try running a PXE/iPXE server alongside `bootcfg` on the docker0 bridge. Use the included `ipxe` container to run an example PXE/iPXE server on that bridge. -The `ipxe` Docker image runs DHCP and sends options to point PXE/iPXE clients to the boot config service (hardcoded to http://172.17.0.2:8080). For PXE clients, iPXE firmware is chainloaded. +The `ipxe` Docker image uses dnsmasq DHCP to point PXE/iPXE clients to the boot config service (hardcoded to http://172.17.0.2:8080). It also runs a TFTP server to serve the iPXE firmware to older PXE clients via chainloading. cd dockerfiles/ipxe ./docker-build ./docker-run -Create a PXE boot client VM or attach a bare metal PXE boot client to the `docker0` virtual bridge. See [clients](#Clients). +Now create local PXE boot [clients](#clients) as libvirt VMs or by attaching bare metal machines to the docker0 bridge. ### PXE @@ -139,33 +139,27 @@ To use `bootcfg` with PXE, you must [chainload iPXE](http://ipxe.org/howto/chain `bootcfg` does not respond to DHCP requests or serve files over TFTP. -#### Pixecore +### Pixecore -Run the Pixiecore server container which uses `api` mode to call through to the config service. +Pixiecore is a ProxyDHCP, TFTP, and HTTP server and calls through to the `bootcfg` API to get a boot config for `pxelinux` to boot. No modification of your existing DHCP server is required in production. - make run-pixiecore +#### docker0 -Finally, run the `vethdhcp` script to create a virtual ethernet connection on the `docker0` bridge, assign an IP address, and run dnsmasq to provide DHCP service to VMs we'll add to the bridge. +Try running a DHCP server, Pixiecore, and `bootcfg` on the docker0 bridge. Use the included `dhcp` container to run an example DHCP server and the official Pixiecore container image. - make run-dhcp + # DHCP + cd dockerfiles/dhcp + ./docker-build + ./docker-run -Create a PXE boot client VM using virt-manager as described above. +Start Pixiecore using the script which attempts to detect the IP and port of `bootcfg` on the Docker host or do it manually. -### Troubleshooting + # Pixiecore + ./scripts/pixiecore + # manual + docker run -v $PWD/images:/images:Z danderson/pixiecore -api http://$BOOTCFG_HOST:$BOOTCFG_PORT/pixiecore -* Check your firewall settings to ensure you've allowed DHCP to run. -* On some platforms, SELinux prevents file serving unless contexts are changed appropriately. -* If you get an "address is already in use" error, try stopping the `default` network created in virt-manager. -* If you find that the `docker0` bridge receives DHCP Offers from dnsmasq, but the VM does not you may need to change an iptables rule. - -Change subnet MASQUERADE. - - $ iptables -L -t nat - $ iptables -t nat -R POSTROUTING 1 -s 172.17.0.0/16 ! -d 172.17.0.0/16 -j MASQUERADE - - POSTROUTING - MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0 (Original Rule 1) - MASQUERADE all -- 172.17.0.0/16 !172.17.0.0/16 (Updated Rule 1) +Now create local PXE boot [clients](#clients) as libvirt VMs or by attaching bare metal machines to the docker0 bridge. ## Clients diff --git a/dockerfiles/dhcp/Dockerfile b/dockerfiles/dhcp/Dockerfile new file mode 100644 index 00000000..a2951ce2 --- /dev/null +++ b/dockerfiles/dhcp/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:latest +MAINTAINER Dalton Hubble +RUN apk -U add dnsmasq +EXPOSE 53 +ENTRYPOINT ["dnsmasq", "-d"] +CMD ["--dhcp-range=172.17.0.43,172.17.0.99,30m"] diff --git a/dockerfiles/dhcp/docker-build b/dockerfiles/dhcp/docker-build new file mode 100755 index 00000000..da640ae0 --- /dev/null +++ b/dockerfiles/dhcp/docker-build @@ -0,0 +1,5 @@ +#!/bin/bash -e + +REPO=dghubble/dhcp + +docker build -q --rm=true -t $REPO:latest . \ No newline at end of file diff --git a/dockerfiles/dhcp/docker-run b/dockerfiles/dhcp/docker-run new file mode 100755 index 00000000..34c0f42c --- /dev/null +++ b/dockerfiles/dhcp/docker-run @@ -0,0 +1,3 @@ +#!/bin/bash -e + +docker run --rm --cap-add=NET_ADMIN dghubble/dhcp diff --git a/scripts/pixiecore b/scripts/pixiecore index 0ca5fc2b..6d843811 100755 --- a/scripts/pixiecore +++ b/scripts/pixiecore @@ -4,8 +4,4 @@ CONFIG_SERVICE=bootcfg CONFIG_SERVICE_IP=$(docker inspect --format {{.NetworkSettings.IPAddress}} ${CONFIG_SERVICE}) CONFIG_SERVICE_PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' ${CONFIG_SERVICE}) -docker run -v $PWD/static:/static danderson/pixiecore -api http://$CONFIG_SERVICE_IP:$CONFIG_SERVICE_PORT/ - - - - +docker run -v $PWD/images:/images:Z danderson/pixiecore -api http://$CONFIG_SERVICE_IP:$CONFIG_SERVICE_PORT/pixiecore