Skip to content

Instantly share code, notes, and snippets.

@brunocmorais
Last active October 18, 2025 23:55
Show Gist options
  • Select an option

  • Save brunocmorais/938cb52b68ff993b3b21bdaa568f83ef to your computer and use it in GitHub Desktop.

Select an option

Save brunocmorais/938cb52b68ff993b3b21bdaa568f83ef to your computer and use it in GitHub Desktop.
How to build a simple and minimalistic BusyBox Docker image from scratch, without pulling it from Docker Hub
#!/usr/bin/env sh
if [ -d rootfs ]
then
rm -rf rootfs/
fi
mkdir rootfs
mkdir rootfs/bin
mkdir rootfs/etc
mkdir rootfs/root
if [ ! -f busybox ]
then
wget https://busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox
fi
chmod +x busybox
echo "root:x:0:0:root:/root:/bin/sh" > rootfs/etc/passwd
echo "root:x:0:" > rootfs/etc/group
docker build . -t simplebusybox
rm -rf rootfs/
rm busybox
docker run -it simplebusybox
FROM scratch
COPY rootfs/ /
COPY busybox /bin
RUN ["./bin/busybox", "--install", "-s", "/bin"]
CMD ["/bin/sh"]
@bittorf
Copy link

bittorf commented Oct 31, 2024

Output in the interactive console is like:

/ # ps
PID   USER     TIME  COMMAND
    1 root      0:00 /bin/sh
    7 root      0:00 ps

/ # find / -xdev -type f -size +0 -exec ls -l {} \;
-rw-------    1 root     root           209 Oct 31 09:35 /root/.ash_history
-rwxr-xr-x    1 root     root       1131168 Jan 17  2022 /bin/busybox
-rw-r--r--    1 root     root            30 Oct 31 09:33 /etc/passwd
-rw-r--r--    1 root     root            10 Oct 31 09:33 /etc/group
-rw-r--r--    1 root     root           237 Oct 31 09:33 /etc/resolv.conf
-rw-r--r--    1 root     root           174 Oct 31 09:33 /etc/hosts
-rw-r--r--    1 root     root            13 Oct 31 09:33 /etc/hostname

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment