Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploy alpine into the filesystem of a container (the PID of the PID1 of the container)
#!/bin/bash
#Based on https://github.com/moby/moby/blob/master/contrib/mkimage-alpine.sh
set -ex
#PID environment variable has to be set.
PID=${PID:-0}
REL=${REL:-edge}
MIRROR=${MIRROR:-http://nl.alpinelinux.org/alpine}
SAVE=${SAVE:-0}
MAINREPO=$MIRROR/$REL/main
ADDITIONALREPO=$MIRROR/$REL/${ADDITIONALREPO:-community}
ARCH=${ARCH:-$(uname -m)}
getapk() {
curl -sSL $MAINREPO/$ARCH/apk-tools-static-$(apkv).apk |
tar -xz -C $ROOTFS sbin/apk.static
}
mkbase() {
$ROOTFS/sbin/apk.static --repository $MAINREPO --update-cache --allow-untrusted \
--root $ROOTFS --initdb add alpine-base
}
conf() {
printf '%s\n' $MAINREPO > $ROOTFS/etc/apk/repositories
printf '%s\n' $ADDITIONALREPO >> $ROOTFS/etc/apk/repositories
}
apkv() {
curl -sSL $MAINREPO/$ARCH/APKINDEX.tar.gz | tar -Oxz |
grep --text '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2
}
ROOTFS="/proc/$PID/root"
getapk
mkbase
conf
echo "You can now enter your formely scratch container with: docker exec -ti container-name sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment