Build Alpine image via Docker #989
-
I wonder whether anyone knows how to build an Alpine image via Docker similar to tools/docker/debian. I'm stuck at mounting the 9p filesystem |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Here is my proof-of-work Alpine Linux on 9pfs, feel free for suggestions. 1. Create Dockerfile FROM i386/alpine:3.18.6
ENV KERNEL=lts
ENV HOSTNAME=localhost
ENV ROOT_PASSWORD=root
# Installing base packages, you can add additional packages here (community repo is enabled)
RUN apk add openrc alpine-base agetty alpine-conf
# Install newer mkinitfs from edge (todo: remove this when 3.19+ has worked properly with 9pfs)
RUN apk add mkinitfs --no-cache --allow-untrusted --repository https://dl-cdn.alpinelinux.org/alpine/edge/main/
# Installing kernel and remove unused drivers for linux-lts
RUN if [ "$KERNEL" == "lts" ]; then \
apk add linux-lts linux-firmware-none; \
else \
apk add linux-$KERNEL; \
fi
# Setting root password and hostname
RUN echo "root:$ROOT_PASSWORD" | chpasswd
RUN setup-hostname $HOSTNAME
# Enable autologin into root on tty1, also you can use autologin.c instead agetty
# (see https://wiki.alpinelinux.org/wiki/TTY_Autologin#By_compiling_your_own_autologin_wrapper)
RUN sed -i 's/getty 38400 tty1/agetty --autologin root tty1 linux/' /etc/inittab
# Adding networking.sh script (works only on lts kernel yet)
# (https://github.com/copy/v86/blob/master/tools/docker/debian/networking.sh)
RUN if [ "$KERNEL" == "lts" ]; then \
echo -e "rmmod ne2k-pci && modprobe ne2k-pci\nhwclock -s\nsetup-interfaces -a -r" > /root/networking.sh && \
chmod +x /root/networking.sh; \
fi
# Enable minimal needed OpenRC services
# (see https://wiki.alpinelinux.org/wiki/Alpine_Linux_in_a_chroot#Preparing_init_services)
RUN for i in devfs dmesg mdev hwdrivers; do rc-update add $i sysinit; done
RUN for i in hwclock modules sysctl hostname syslog bootmisc; do rc-update add $i boot; done
RUN rc-update add killprocs shutdown
# Generate initramfs with 9p modules
RUN mkinitfs -F "ata base ide scsi virtio ext4 9p" $(cat /usr/share/kernel/$KERNEL/kernel.release) 2. Create image container following by tools/docker/debian/build-container.sh v86/tools/docker/debian/build-container.sh Lines 11 to 16 in 360d569 "$(dirname "$0")"/../../../tools/fs2json.py --exclude /.dockerenv --out "$OUT_FSJSON" "$OUT_ROOTFS_TAR"
# make sure that .dockerenv not included in fs.json (if this happened, remove it from "fsroot" in json) v86/tools/docker/debian/build-container.sh Lines 20 to 22 in 360d569 3. Extract kernel and initrd tar -zxf "$OUT_ROOTFS_TAR" --strip-components=1 boot/*-<lts or virt> 4. Add to var emulator = new V86({
...
bzimage: {
url: "vmlinuz-...",
},
initrd: {
url: "initramfs-...",
},
filesystem: {
baseurl: "path/to/OUT_ROOTFS_FLAT/",
basefs: "path/to/OUT_FSJSON",
},
bzimage_initrd_from_filesystem: false,
cmdline: [
"rw",
"root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose",
"nowatchdog"
].join(" "),
}); Notes:
|
Beta Was this translation helpful? Give feedback.
Here is my proof-of-work Alpine Linux on 9pfs, feel free for suggestions.
1. Create Dockerfile