dhcpcd system container

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
Riyaz Faizullabhoy
2017-03-15 12:18:10 +00:00
parent 08e62e0ebd
commit a33b9ff4b1
15 changed files with 233 additions and 10 deletions

5
pkg/dhcpcd/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
bin
dev
proc
sys
usr

38
pkg/dhcpcd/10-mtu Normal file
View File

@@ -0,0 +1,38 @@
# Configure the MTU for the interface
mtu_dir="$state_dir/mtu"
set_mtu()
{
local mtu=$1
if [ -w /sys/class/net/$interface/mtu ]; then
echo "$mtu" >/sys/class/net/$interface/mtu
else
ifconfig "$interface" mtu "$mtu"
fi
}
if [ "$reason" = PREINIT -a -e "$mtu_dir/$interface" ]; then
rm "$mtu_dir/$interface"
elif [ -n "$new_interface_mtu" ] && $if_up; then
# The smalled MTU dhcpcd can work with is 576
if [ "$new_interface_mtu" -ge 576 ]; then
if set_mtu "$new_interface_mtu"; then
syslog info "$interface: MTU set to $new_interface_mtu"
# Save the MTU so we can restore it later
if [ ! -e "$mtu_dir/$interface" ]; then
mkdir -p "$mtu_dir"
echo "$ifmtu" > "$mtu_dir/$interface"
fi
fi
fi
elif [ -e "$mtu_dir/$interface" ]; then
if $if_up || $if_down; then
# No MTU in this state, so restore the prior MTU
mtu=$(cat "$mtu_dir/$interface")
syslog info "$interface: MTU restored to $mtu"
set_mtu "$mtu"
rm "$mtu_dir/$interface"
fi
fi

14
pkg/dhcpcd/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM alpine:3.5
RUN \
apk update && apk upgrade -a && \
apk add --no-cache \
dhcpcd \
openrc \
&& true
ADD dhcpcd.conf /dhcpcd.conf
ADD start_dhcpcd.sh /usr/local/bin/start_dhcpcd.sh
ADD 10-mtu /usr/lib/dhcpcd/dhcpcd-hooks/10-mtu
CMD ["/usr/local/bin/start_dhcpcd.sh"]

34
pkg/dhcpcd/Makefile Normal file
View File

@@ -0,0 +1,34 @@
.PHONY: tag push clean container
default: push
IMAGE=dhcpcd
BASE=alpine:3.5
DEPS=dhcpcd.conf 10-mtu start_dhcpcd.sh
container: Dockerfile $(DEPS)
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
hash: Dockerfile $(DEPS)
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --rm $(IMAGE):build sh -c '(cat /usr/local/bin/start_dhcpcd.sh /dhcpcd.conf /usr/lib/dhcpcd/dhcpcd-hooks/10-mtu /lib/apk/db/installed) | sha1sum' | sed 's/ .*//' > hash
push: hash container
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
docker push mobylinux/$(IMAGE):$(shell cat hash))
docker rmi $(IMAGE):build
rm -f hash
tag: hash container
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
docker rmi $(IMAGE):build
rm -f hash
clean:
rm -rf hash $(DIRS)
.DELETE_ON_ERROR:

43
pkg/dhcpcd/dhcpcd.conf Normal file
View File

@@ -0,0 +1,43 @@
# Moby dhcpcd config
# Only configure standard external ethernet
allowinterfaces eth*
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# Do not wait
nodelay
# Do not arp to check IP
noarp

9
pkg/dhcpcd/start_dhcpcd.sh Executable file
View File

@@ -0,0 +1,9 @@
#!bin/sh
set -ex
ip link set eth0 up
cp /dhcpcd.conf /etc/dhcpcd.conf
/sbin/dhcpcd --nobackground

View File

@@ -4,7 +4,6 @@ RUN \
apk --no-cache update && \
apk --no-cache upgrade -a && \
apk --no-cache add \
dhcpcd \
&& rm -rf /var/cache/apk/*
COPY . ./

View File

@@ -102,5 +102,7 @@ ip addr add 127.0.0.1/8 dev lo brd + scope host
ip route add 127.0.0.0/8 dev lo scope host
ip link set lo up
# will be containerised
/sbin/dhcpcd
# for containerising dhcpcd and other containers that need writable etc
mkdir /tmp/etc
mv /etc/resolv.conf /tmp/etc/resolv.conf
ln -snf /tmp/etc/resolv.conf /etc/resolv.conf