This commit is contained in:
Matteo Carnelos 2023-03-16 10:18:37 +00:00 committed by GitHub
commit 734286f0fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -61,6 +61,28 @@ docker run -it lukechilds/dockerpi pi3
> **Note:** In the Pi 2 and Pi 3 machines, QEMU hangs once the machines are powered down requiring you to `docker kill` the container. See [#4](https://github.com/lukechilds/dockerpi/pull/4) for details.
## Port forwarding
In some applications you may want to have access to some ports of the Raspberry Pi (e.g. for SSH connection). To do so, you can set the `QEMU_HOSTFWD` enviroment variable of the container by adding one or more entries, separated by spaces, in the standard QEMU format (`protocol::hostip:hostport-guestip:guestport`).
Example using the `docker run` command to expose the SSH and MQTT ports from the Raspberry Pi to the Container (`-e` part) and from the Container to the Host (`-p` part):
```
docker run -it -e QEMU_HOSTFWD="tcp::5022-:22 tcp::1883-:1883" -p 5022:5022 -p 1883:1883 lukechilds/dockerpi
```
Example using the `docker-compose.yml` file to achieve the same result:
```yml
services:
dockerpi:
image: lukechilds/dockerpi
environment:
- QEMU_HOSTFWD=tcp::5022-:22 tcp::1883-:1883
ports:
- "5022:5022"
- "1883:1883"
```
## Wait, what?

View file

@ -25,6 +25,8 @@ if [[ "$(($image_size_in_bytes % ($GIB_IN_BYTES * 2)))" != "0" ]]; then
qemu-img resize $image_path "${new_size_in_gib}G"
fi
for fwd in $QEMU_HOSTFWD; do hostfwd="$hostfwd,hostfwd=$fwd"; done
if [ "${target}" = "pi1" ]; then
emulator=qemu-system-arm
kernel="/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
@ -32,7 +34,7 @@ if [ "${target}" = "pi1" ]; then
machine=versatilepb
memory=256m
root=/dev/sda2
nic="--net nic --net user,hostfwd=tcp::5022-:22"
nic="--net nic --net user$hostfwd"
elif [ "${target}" = "pi2" ]; then
emulator=qemu-system-arm
machine=raspi2b
@ -40,7 +42,7 @@ elif [ "${target}" = "pi2" ]; then
kernel_pattern=kernel7.img
dtb_pattern=bcm2709-rpi-2-b.dtb
append="dwc_otg.fiq_fsm_enable=0"
nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
nic="-netdev user,id=net0$hostfwd -device usb-net,netdev=net0"
elif [ "${target}" = "pi3" ]; then
emulator=qemu-system-aarch64
machine=raspi3b
@ -48,7 +50,7 @@ elif [ "${target}" = "pi3" ]; then
kernel_pattern=kernel8.img
dtb_pattern=bcm2710-rpi-3-b-plus.dtb
append="dwc_otg.fiq_fsm_enable=0"
nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
nic="-netdev user,id=net0$hostfwd -device usb-net,netdev=net0"
else
echo "Target ${target} not supported"
echo "Supported targets: pi1 pi2 pi3"