Skip to content

Instantly share code, notes, and snippets.

@bootjp
Forked from yangxuan8282/Dockerfile.dnsmasq
Created July 25, 2021 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootjp/0b6cc2f73259d60d833a18478d0b7f0a to your computer and use it in GitHub Desktop.
Save bootjp/0b6cc2f73259d60d833a18478d0b7f0a to your computer and use it in GitHub Desktop.
pi netboot with docker

⚠️ NFS server version 3 in docker behavior is strange, it won't work after restart the containter, and seems raspberry pi kernel have not supported netboot from vers 4 yet(will got kernel panic), so use docker to do this is not reliable for now, if we want to make container work again after stopped we have to restart the host.

☞ use this compose: https://github.com/yangxuan8282/rpi3-pxe-docker , this is the working one

port=0
dhcp-range=192.168.1.255,proxy
log-dhcp
enable-tftp
tftp-root=/tftpboot
pxe-service=0,"Raspberry Pi Boot"
version: "2"
services:
netboot_boot:
image: local/dnsmasq
privileged: true
network_mode: "host"
volumes:
- ./boot:/tftpboot
- ./dnsmasq.conf:/etc/dnsmasq.conf
netboot_root:
image: local/nfs-server
privileged: true
network_mode: "host"
volumes:
# - ./exports:/etc/exports
- ./rootfs:/nfsshare
FROM arm32v6/alpine
RUN apk add --no-cache dnsmasq
EXPOSE 53/tcp \
53/udp \
67/udp
ENTRYPOINT ["dnsmasq", "--no-daemon", "--user=dnsmasq", "--group=dnsmasq"]
FROM arm32v6/alpine
RUN apk --update --no-cache add bash nfs-utils \
&& echo "/nfs/client1 *(rw,sync,no_subtree_check,no_root_squash)" | tee -a /etc/exports
COPY run_nfs /usr/bin/
COPY exports /etc/exports
#VOLUME /nfs/client1
ENTRYPOINT ["run_nfs"]
/nfsshare *(rw,sync,no_subtree_check,no_root_squash)
#!/bin/bash
set -xe
trap "stop; exit 0;" SIGTERM SIGINT
stop()
{
# We're here because we've seen SIGTERM, likely via a Docker stop command or similar
# Let's shutdown cleanly
echo "SIGTERM caught, terminating NFS process(es)..."
/usr/sbin/exportfs -ua
pid1=$(pidof rpc.nfsd)
pid2=$(pidof rpc.mountd)
kill -TERM $pid1 $pid2 > /dev/null 2>&1
echo "Terminated."
exit
}
mkdir -p /nfsshare
# Fixed nlockmgr port
#echo 'fs.nfs.nlm_tcpport=32768' >> /etc/sysctl.conf
#echo 'fs.nfs.nlm_udpport=32768' >> /etc/sysctl.conf
#sysctl -p > /dev/null
mount -t nfsd nfds /proc/fs/nfsd
rpcbind -w
rpc.nfsd -N 2 -V 3 -N 4 -N 4.1 8
exportfs -arfv
rpc.statd
rpc.mountd -N 2 -V 3 -N 4 -N 4.1 -F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment