Skip to content

Instructions to use sdm inside a Docker container #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions Docs/Using-Docker.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
# Using Docker

sdm does not currently work with Docker.
sdm can work from within a Docker container.

If you are interested in seeing this work, AND are fairly Docker-enlightened, please consider providing me with a "sdm on Docker" cookbook that an unenlightened Docker user like me can follow.
Some reasons to do this are:
- reliable and repeatable image creation (much in the spirit of sdm)
- one might dislike the dependencies of sdm (e.g. as installed by EZsdmInstaller)
- one might dislike to run so many "scary" (e.g. fdisk, ...) commands as root on important systems
- one might dislike to run shell scripts freshly downloaded from the Internet (in particular as root)

Once such a guide is provided and I am able to verify that it works, I'll include it in the sdm Documentation.
But in order to function, sdm still needs elevated permissions (e.g. for losetup and mount calls), so the `--priviledged` flag to docker is required. That flag means the docker container can protect against mistakes by the sdm developers, but won't prevent malicious attacks.

First (after making sure that `sudo docker run hello-world` does work well), create a script `myscript.sh` that you want to run inside the container:

```
#!/bin/bash

# prepare the environment and download sdm
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get --yes install fdisk git file binfmt-support systemd binfmt-support gdisk keyboard-configuration parted qemu-user-static rsync systemd-container uuid
git clone https://github.com/gitbls/sdm

# customize the image. Probably add many more --plugin lines here
sdm/sdm --customize --sdmdir /root/sdm \
--plugin sshd:"password-authentication=no" \
--plugin disables:piwiz \
/root/sdm_working_dir/2024-11-19-raspios-bookworm-armhf-lite.img

# burn the image
sdm/sdm --sdmdir /root/sdm \
--burnfile /root/sdm_working_dir/burned.img \
--host somepi \
/root/sdm_working_dir/2024-11-19-raspios-bookworm-armhf-lite.img
```

See <a href="Example-Burn-Multiple-Hosts-From-Single-IMG.md">Example-Burn-Multiple-Hosts-From-Single-IMG</a> for an idea how to burn many images in one loop.

Second, prepare a directory to inject into the container:
```
mkdir working_dir
cd working_dir
wget https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2024-11-19/2024-11-19-raspios-bookworm-armhf-lite.img.xz
unxz 2024-11-19-raspios-bookworm-armhf-lite.img.xz
cd ..
```

Third, execute!

```
sudo docker run --privileged --network host --rm \
-v "$(pwd)/myscript.sh:/myscript.sh" \
-v "$(pwd)/working_dir:/root/sdm_working_dir" \
--device=/dev/loop-control \
--device=/dev/loop0 \
debian:latest bash /myscript.sh
```

<br>
<form>
Expand Down