• Stars
    star
    250
  • Rank 158,664 (Top 4 %)
  • Language
    Shell
  • Created over 10 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dockerfile to build a PXE server in a Docker container

My other PXE server is a container

This is a Dockerfile to build a container running a PXE server, pre-configured to serve a Debian netinstall kernel and initrd.

Quick start

  1. Of course you need Docker first!
  2. Clone this repo and cd into the repo checkout.
  3. Build the container with docker build -t pxe .
  4. Run the container with PXECID=$(docker run --cap-add NET_ADMIN -d pxe)
  5. Give it an extra network interface with ./pipework br0 $PXECID 192.168.242.1/24
  6. Put the network interface connected to your machines on the same bridge with e.g. brctl addif br0 eth0 (don't forget to move eth0 IP address to br0 if there is one).
  7. You can now boot PXE machines on the network connected to eth0! Alternatively, you can put VMs on br0 and achieve the same result.

Why and how do we move eth0 IP address to br0?

The Linux network stack has the notion of master and slave interfaces. They are used in many places, including bridges and bonding (when multiple physical interfaces are grouped together to form a single logical link, for increased throughput or reliability). When using Linux bridges, the bridge is the master interface, and all the ports of the bridge are slave interfaces.

Now is the tricky part: with interfaces like bridges and bonding groups, only the master should have IP addresses; not the slaves. If an IP address is configured on a slave interface, it will misbehave in seemingly random ways. For instance, it can stop working if the interface is down (but the master interface is still up). Or it might handle some protocols like ARP only for packets inbound on this interface.

Therefore, when changing the configuration of an existing interface to place it inside a bridge (or bonding group), you should deconfigure its IP address, and assign it to the master interface instead. I recommend the following steps:

  1. Check the IP address of the interface (with e.g. ip addr ls eth0). Carefully note the IP address and its subnet mask, e.g. 192.168.1.4/24. There can be multiple addresses; in that case, note all of them.
  2. Check if there are special routes going through that interface. Chances are, that there is a default route, and you will have to take care of it; otherwise you will lose internet connectivity. The easiest way is to do ip route ls dev eth0. You will almost certainly see an entry with proto kernel scope link, which is the automatic entry corresponding to the subnet directly connected to this interface. You can ignore this one. However, if you see something like default via 192.168.1.1, note it.
  3. Deconfigure the IP address. In that case, we would do ip addr del 192.168.1.4/24 dev eth0. You don't havea to deconfigure the routes: they will be automatically removed as the address is withdrawn.
  4. Configure the IP address on the bridge. In our example, that would be ip addr add 192.168.1.4/24 dev br0.
  5. Last but not least, re-add the routes on the bridge. Here, we would do ip route add default via 192.168.1.1.

If you want to do that automatically at boot, you can do it through the /etc/network/interfaces file (on Debian/Ubuntu).

It will look like this (assuming the same IP addresses than our previous example):

auto br0
iface br0 inet static
      address 192.168.1.4
      netmask 255.255.255.0
      network 192.168.1.0
      broadcast 192.168.1.255
      gateway 192.168.1.1
      bridge_ports eth0
      bridge_stp off
      bridge_fd 0

Don't forget to disable the section related to eth0 then!

I want to netboot something else!

Left as an exercise for the reader. Check the Dockerfile and rebuild; it should be easy enough.

If you want to boot coreOS, check out avlis/pxe_coreos

It doesn't work!

That's unfortunate. You should probably adapt these instructions to use host networking (i.e. --net host) since this recipe was written before host networking was available. Meanwhile, if you have strange symptoms (like, some things ping and some don't) you might have to disable bridge netfilter filtering. Please look at issue #17 for more details.

Can I change the IP address, 192.168.242.1...?

Yes. Be aware that the DHCP server on this container will offer IPs from 101 to 199 on the same /24 subnet. So make sure that the IP you give to the container via pipework does not clash with that. Also make sure that there are no other hosts on that bridge within that range. Otherwise, change it in the Dockerfile, check the line that says --dhcp-range=(...).

Can I not use pipework?

Yes, but it will be more complicated. You will have to:

  • make sure that Docker UDP can handle broadcast packets (since PXE/DHCP uses broadcast packets);
  • make sure that UDP ports are correctly mapped;
  • auto-detect the gateway address and DNS server, instead of using the container as a router+DNS server;
  • maybe something else that I overlooked.

I want MOAR fun!

Let's have a game!

  1. Burn a boot2docker ISO on a blank CD.
  2. With that CD, boot a physical machine.
  3. Run the PXE container on Docker on the physical machine.
  4. Pull the ubuntu container, start it in privileged mode, apt-get install QEMU in it, and start a QEMU VM, mapping its hard disks to the real hard disk of the machine, and bridging it with the PXE container.
  5. The QEMU VM will netboot from the PXE container. Install Debian.
  6. Reboot the physical machine -- it now boots on Debian.
  7. Repeat steps but install Windows for trolling purposes.

Did anyone make something useful with this?

Yes!

  • @dreamcat4 used this as inspiration for a bunch of pxe images
  • @kkredit used this as the basis for a CI setup tied to Jenkins and multiple hardware targets
  • _________ (insert your name here, by submitting a PR to this README file! ;-))

More Repositories

1

pipework

Software-Defined Networking tools for LXC (LinuX Containers)
Shell
4,139
star
2

container.training

Slides and code samples for training, tutorials, and workshops about Docker, containers, and Kubernetes.
Shell
3,559
star
3

nsenter

Shell
2,582
star
4

ampernetacle

HCL
2,519
star
5

dind

Docker in Docker
Shell
2,474
star
6

dockvpn

Recipe to build an OpenVPN image for Docker
Shell
833
star
7

squid-in-a-can

Python
357
star
8

minimage

Minimal Docker images: a collection of Dockerfiles illustrating how to reduce container image size.
Shell
206
star
9

griode

Griode + Novation Launchpad + Raspberry Pi = a music instrument!
Python
139
star
10

registrish

Dirty hack to run a read-only, public Docker registry on almost any static file hosting service (e.g. NGINX, Netlify, S3...)
Shell
136
star
11

shpod

Container image to get a consistent training environment to work on Kubernetes.
Dockerfile
134
star
12

critmux

Docker + CRIU + tmux = magic!
Dockerfile
117
star
13

dockercoins

Python
98
star
14

docker-busybox

Busybox for Stackbrew
Shell
94
star
15

sekexe

Separate Kernel Execution: execute a process within user-mode-linux and retrieve its output and status code
Shell
79
star
16

dessine-moi-un-cluster

Instructions to build a Kubernetes control plane one piece at a time, for learning purposes.
Shell
78
star
17

gunsub

Get your github notifications under control!
Python
74
star
18

syslogdocker

70
star
19

stevedore

Containerize your development environments
Shell
68
star
20

hamba

Shell
67
star
21

obs-docker

OBS-Studio (and a few extra tools) in containers
Python
62
star
22

docker2docker

Shell
26
star
23

wordsmith

Java
23
star
24

intro-to-docker

CSS
23
star
25

jpetazzo.github.io

HTML
22
star
26

go-docker-

20
star
27

trainingwheels

HTML
18
star
28

snakedeck

Elgato StreamDeck controller for Linux, in Python.
Python
17
star
29

nsplease

Tiny Kubernetes operator to create Namespaces on demand (for CI/CD, for instance)
Shell
16
star
30

django

Django on DotCloud tutorial
Python
16
star
31

whisperfiles

A bunch of Dockerfiles for OpenAI Whisper, to illustrate various image optimization techniques
Shell
15
star
32

foundation-example

Shell
14
star
33

httpenv

Tiny HTTP server showing the environment variables
Go
14
star
34

buildkit-demos

Dockerfile
13
star
35

dctrl

Shell
13
star
36

orchestration-workshop

We have moved! We are now at β†’ https://github.com/jpetazzo/container.training
HTML
12
star
37

decoup

Python
11
star
38

layeremove

Surgically remove layers from a Docker image (with a chainsaw)
Python
11
star
39

znc-on-dotcloud

Shell
11
star
40

tilestream-on-dotcloud

Python
10
star
41

littleboxes

Just for fun scripts to manage local cloud-like VMs with KVM
Shell
10
star
42

django-and-mongodb-on-dotcloud

Django on DotCloud tutorial, using MongoDB to store objects!
Python
10
star
43

kubercoins

8
star
44

sstk

Shell
8
star
45

geodjango-on-dotcloud

Python
7
star
46

meteor-on-dotcloud

7
star
47

solr-on-dotcloud

JavaScript
7
star
48

seleterm

Selenium for terminal applications
Python
6
star
49

snap-on-dotcloud

Shell
6
star
50

httplat

Minimalist Prometheus exporter to collect the latency of an HTTP target
Go
6
star
51

boggle

Solver for the Boggle Word Game
Python
6
star
52

mume

Python
6
star
53

gitorial

(Ab)use git history to write tutorials!
Python
6
star
54

postgresql-on-dotcloud

Python
5
star
55

django-on-gpaas

Django on GANDI PAAS
Python
5
star
56

scangraph

Retrieve point coordinates from a raster plot
JavaScript
5
star
57

hano

Online IDE for Node.js on dotCloud
Shell
5
star
58

pyramid-on-dotcloud

Python
5
star
59

traefik-compose

Quick demo showing how to run web sites (like Wordpress) on Docker with Traefik
4
star
60

plumber

Shell
4
star
61

consul

jpetazzo's Consul image
Shell
4
star
62

zwave-exporter

Prometheus exporter for Z-Wave sensors
JavaScript
4
star
63

jenkins-on-dotcloud

Shell
4
star
64

color

Go
4
star
65

busyhttp

A trivial HTTP server that eats CPU cycles at each request.
Python
4
star
66

tinydocgen

Tiny document generator using Jinja2, Markdown, and WeasyPrint.
Makefile
3
star
67

ngrok

3
star
68

charliebot

Python
3
star
69

prettypictures

3
star
70

usb-webcam-analyzer

Python
3
star
71

rickroll-in-docker

HTML
3
star
72

dnc

Domain Name Command-line tool
Python
3
star
73

python-simple-logging

Python
3
star
74

replay.container.training

Shell
3
star
75

riak-on-dotcloud-ALPHA

Shell
3
star
76

ucengine-on-dotcloud-ALPHA

Shell
3
star
77

django-r2d2

R2D2 (RRDDashboard) is a Django application to draw graphs from metrics coming from e.g. collectd.
Python
3
star
78

pieuvre

Distributed HTTP proxy in Node.js
JavaScript
2
star
79

tmp-sealedsecret-juin-2022

2
star
80

couchdb-on-dotcloud-ALPHA

Shell
2
star
81

escapehash

Python
2
star
82

dockerhubratelimit

Shell
2
star
83

workflows

2
star
84

python-worker-on-dotcloud

Shell
2
star
85

tcl-on-dotcloud-ALPHA

Shell
2
star
86

elastic-gke

HCL
2
star
87

dampmam

Docker-Apache-MySQL-PHP but without Apache and MySQL
JavaScript
2
star
88

watchdns

Shell
2
star
89

highfive

Dockerfile
2
star
90

memcached-on-dotcloud

2
star
91

pawd

PulseAudio Web Daemon
2
star
92

pingr

HTTP server to ping other servers and report their status
Go
2
star
93

dotfiles-old

Config files for various environments
Shell
2
star
94

pgpool-II-on-dotcloud

2
star
95

ls

An ls image for the Docker Fundamentals training
Shell
2
star
96

jetty-on-dotcloud

Reimplementation of dotCloud java service using the custom build API
Shell
2
star
97

dockage

Shell
2
star
98

jira-on-dotcloud

Shell
2
star
99

tornado-on-dotcloud

Python
2
star
100

aiguillage

Nginx
2
star