Install Docker
Straight forward Docker installation, see recap below
- New installation of Raspbian
- sudo apt-get update && sudo apt-get upgrade
- Install Docker
- Manually according docker
- or
- A Docker installation script
- curl -fsSL https://get.docker.com -o get-docker.sh
- sudo sh get-docker.sh
- Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
- <…>
- Add a Non-Root User to the Docker Group >
- sudo usermod -aG docker ${USER}
- Test > groups ${USER}
- Autostart Docker Service
- sudo systemctl enable docker
- Check service > sudo systemctl status docker.service
- Test docker Installation
- docker run hello-world
- Test simple server with information about the raspberry
- docker run -d -p 8080:8080 pmorjan/demo:latest
- Go to IP address:8080 to see the result
Install Log2ram to reduce write actions
https://github.com/azlux/log2ram
echo “deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bullseye main” | sudo tee /etc/apt/sources.list.d/azlux.list
sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg https://azlux.fr/repo.gpg
sudo apt update
sudo apt install log2ram
Reboot
Create .yaml file with Portainer
version of docker compose
version: ‘3’
services:
portainer-ce:
container_name: portainer-ce
image: portainer/portainer-ce
restart: unless-stopped
ports:
– “8000:8000”
– “9000:9000”
volumes:
– /var/run/docker.sock:/var/run/docker.sock
– ./volumes/portainer-ce/data:/data
Docker tips
- To get a docker image use docker pull
- Docker pull > docker pull [OPTIONS] NAME[:TAG|@DIGEST]
- example > docker pull nodered/node-red
- to create a docker container use docker run
- Needs to be done once afterwards you can use docker start/stop
- Creates a container with an image and some variables such as port forwarding, friendly name, volume to connect to
- docker run -d -p “hostport:containerport”” -v “host directory: container directory” –name “friendly name” “image name”
- -d > detached from shell
- -p > port forward “host port:container port”
- -v > folder forwarding “host directory: container directory”
- –name “friendly name”
- example > docker run -d -p 1234:1880 -v “/home/pi/NodeRed:/data –name NodeRed1 nodered/node-red
- Docker start > docker start [OPTIONS] CONTAINER [CONTAINER…]
- docker start “container ID or friendly name”
- docker ps -a > show all containers running or not runningdocker
- images ls > show all stored images
- docker logs -f > shows log output (-f > continuously)
- docker logs -f ssh-honeypotd3
- docker container rm “container ID”
- docker container prune > deletes all stopt containers
- docker image prune -a > deletes all unused images
Portainer – Add container
- First create a volume for data outside the container
- Userfriendly name
- rest default
- Second create a container
- Name > Friendly name for your container
- Registry > Where your image is hosted (normally DockerHub)
- Image > The name of the image you want to deploy (use search and copy the name from docker pull)
- Ports > Expose the desired ports
- Advanced Settings
- Volume > to store data outside the image
- container > /data > volume
- volume > Userfriendly name > writable
- Network > Bridge (Application acts as stand alone)
Homeassistant
- Name HomeAssistant
- Image: homeassistant/home-assistant:latest
- first create the directory /HomeAssistant
- volumes container: /home/pi/HomeAssistant/config > Host /HomeAssistant
- volumes: container: /etc/localtime > host: /etc/localtime
- Network host
- Restart policy unless start
- Runtime & Resources: privileged mode enabled
A simple container to with information about the Raspberry is “pmorjan/demo:latest”
Mosquitto in Docker
docker-compose.yml
mosquitto:
container_name: mosquitto
image: eclipse-mosquitto
restart: unless-stopped
user: “1883”
ports:
– 1883:1883
– 9001:9001
volumes:
– ./volumes/mosquitto/data:/mosquitto/data
– ./volumes/mosquitto/log:/mosquitto/log
– ./services/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
– ./services/mosquitto/pwfile:/mosquitto/config/pwfile #added for security
mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
#password_file /mosquitto/config/pwfile #remove hashtag to apply username and password
Create password file
– In directory ~/IOTstack/services/mosquitto
execute – bash terminal.sh
execute – mosquitto_passwd -c /mosquitto/config/pwfile MYUSER
Restart Mosquitto
MQTT-NodeRed-InfluxDB
In Node Red install the node-red-contrib-influxdb node
- Create a database in influxdb
- Connect to influxdb > docker exec -it influxdb /bin/bash
- enter the comandline enviroment > influx
- CREATE DATABASE heating_rv14
- to check > show databases
Update Portainer-ce
- sudo docker container ls
- sudo docker stop portainer-ce or ID
- sudo docker rm portainer-ce or ID
- sudo docker pull portainer/portainer-ce:latest
- sudo docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 –name=portainer-ce –restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /home/pi/IOTstack/volumes/portainer-ce/data:/data portainer/portainer-ce:latest
- LE
- sudo docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 –name=portainer-ce –restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /home/pi/volumes/portainer-ce/data:/data portainer/portainer-ce
Portainer lost password
- sudo docker stop portainer-ce
- docker run –rm -v /home/pi/volumes/portainer-ce/data:/data portainer/helper-reset-password
- sudo docker start portainer-ce
Docker data on external drive
Je zei:
iotstack boot from sd card and data external drive
ChatGPT zei:
Booting an IoTStack setup from an SD card while storing data on an external drive (USB SSD/HDD) is a common approach to improve performance and reliability on a Raspberry Pi, especially for setups using containers like Docker.
Here’s a clear breakdown of how to do this effectively:
✅ Goal:
- OS and bootloader: Lives on the SD card
- IoTStack data and containers: Stored on external USB drive (e.g.,
/mnt/iotdata)
🛠️ Setup Steps
1. Install Raspberry Pi OS on the SD Card
Use the Raspberry Pi Imager:
- Choose a Lite or Full Raspberry Pi OS (64-bit recommended for Docker)
- Flash to SD card
Boot the Pi.
2. Prepare the External Drive
SSH into the Pi or open terminal:
lsblkFind the external drive (e.g.,
/dev/sda)Format it (EXT4 example):
sudo umount /dev/sda1 sudo mkfs.ext4 /dev/sda⚠️ Warning: This will erase all data on the drive.
3. Mount the External Drive at Boot
Create mount point:
sudo mkdir -p /mnt/iotdataGet UUID of the drive:
sudo blkidCopy the UUID (e.g.,
UUID=abcd-1234)Edit
/etc/fstab:sudo nano /etc/fstabAdd:
UUID=abcd-1234 /mnt/iotdata ext4 defaults,noatime 0 2Test the mount:
sudo mount -a df -hYou should see
/mnt/iotdatamounted.
4. Install IoTStack on External Drive
Clone IoTStack repo to external drive:
cd /mnt/iotdata git clone https://github.com/SensorsIot/IOTstack.git cd IOTstack ./menu.shIoTStack will now be configured and run from the external drive.
5. Make Docker Use External Drive (Optional)
If you want Docker containers and volumes to be on the external drive:
Stop Docker:
sudo systemctl stop dockerMove Docker directory:
sudo mv /var/lib/docker /mnt/iotdata/dockerCreate symlink:
sudo ln -s /mnt/iotdata/docker /var/lib/dockerStart Docker:
sudo systemctl start docker
✅ Benefits
- Reduces wear on SD card (OS reads mostly, writes minimal)
- USB SSD/HDD is much faster and more reliable
- Easier to back up your entire stack (just the external drive)
⚠️ Tips
- Use a good quality power supply – SSDs can be power-hungry.
- Use USB 3.0 ports (on Pi 4 or newer) for faster I/O.
- Make sure external drive mounts before Docker starts on boot —
fstabentry should be correct and stable.
If you’re using Raspberry Pi 4+, you can optionally boot entirely from the SSD (no SD card), but if your intent is specifically “boot from SD, data on USB,” the method above is optimal.
Would you like a bash script to automate the whole setup?
Je zei:
iotstack boot from sd card and data external drive
ChatGPT zei:
Booting an IoTStack setup from an SD card while storing data on an external drive (USB SSD/HDD) is a common approach to improve performance and reliability on a Raspberry Pi, especially for setups using containers like Docker.
Here’s a clear breakdown of how to do this effectively:
✅ Goal:
- OS and bootloader: Lives on the SD card
- IoTStack data and containers: Stored on external USB drive (e.g.,
/mnt/iotdata)
🛠️ Setup Steps
1. Install Raspberry Pi OS on the SD Card
Use the Raspberry Pi Imager:
- Choose a Lite or Full Raspberry Pi OS (64-bit recommended for Docker)
- Flash to SD card
Boot the Pi.
2. Prepare the External Drive
SSH into the Pi or open terminal:
lsblkFind the external drive (e.g.,
/dev/sda)Format it (EXT4 example):
sudo umount /dev/sda1 sudo mkfs.ext4 /dev/sda⚠️ Warning: This will erase all data on the drive.
3. Mount the External Drive at Boot
Create mount point:
sudo mkdir -p /mnt/iotdataGet UUID of the drive:
sudo blkidCopy the UUID (e.g.,
UUID=abcd-1234)Edit
/etc/fstab:sudo nano /etc/fstabAdd:
UUID=abcd-1234 /mnt/iotdata ext4 defaults,noatime 0 2Test the mount:
sudo mount -a df -hYou should see
/mnt/iotdatamounted.
4. Install IoTStack on External Drive
Clone IoTStack repo to external drive:
cd /mnt/iotdata git clone https://github.com/SensorsIot/IOTstack.git cd IOTstack ./menu.shIoTStack will now be configured and run from the external drive.
5. Make Docker Use External Drive (Optional)
If you want Docker containers and volumes to be on the external drive:
Stop Docker:
sudo systemctl stop dockerMove Docker directory:
sudo mv /var/lib/docker /mnt/iotdata/dockerCreate symlink:
sudo ln -s /mnt/iotdata/docker /var/lib/dockerStart Docker:
sudo systemctl start docker
✅ Benefits
- Reduces wear on SD card (OS reads mostly, writes minimal)
- USB SSD/HDD is much faster and more reliable
- Easier to back up your entire stack (just the external drive)
⚠️ Tips
- Use a good quality power supply – SSDs can be power-hungry.
- Use USB 3.0 ports (on Pi 4 or newer) for faster I/O.
- Make sure external drive mounts before Docker starts on boot —
fstabentry should be correct and stable.
If you’re using Raspberry Pi 4+, you can optionally boot entirely from the SSD (no SD card), but if your intent is specifically “boot from SD, data on USB,” the method above is optimal.
Would you like a bash script to automate the whole setup?
Je zei:
please
ChatGPT zei:
Here’s a bash script that automates the key parts of your setup:
- Mounting the external USB drive
- Moving Docker’s data directory
- Cloning IoTStack to the external drive
⚠️ Prerequisites:
- You’ve booted from an SD card with Raspberry Pi OS installed
- You have a USB drive connected (and it’s visible as
/dev/sda)- This script formats the drive — all data will be erased
🧰 Script:
iotstack-usb-setup.sh#!/bin/bash # === CONFIGURABLE VARIABLES === DEVICE="/dev/sda" MOUNT_POINT="/mnt/iotdata" DOCKER_DIR="$MOUNT_POINT/docker" IOTSTACK_DIR="$MOUNT_POINT/IOTstack" # === STEP 1: Confirm user wants to continue === echo "WARNING: This will ERASE all data on $DEVICE!" read -p "Type 'YES' to continue: " confirm if [ "$confirm" != "YES" ]; then echo "Aborted." exit 1 fi # === STEP 2: Format the USB drive === echo "[1/6] Formatting $DEVICE as ext4..." sudo umount ${DEVICE}* 2>/dev/null sudo mkfs.ext4 -F $DEVICE # === STEP 3: Create mount point and get UUID === echo "[2/6] Creating mount point at $MOUNT_POINT..." sudo mkdir -p $MOUNT_POINT UUID=$(sudo blkid -s UUID -o value $DEVICE) FSTAB_LINE="UUID=$UUID $MOUNT_POINT ext4 defaults,noatime 0 2" echo "[3/6] Adding mount to /etc/fstab..." grep -q "$UUID" /etc/fstab || echo "$FSTAB_LINE" | sudo tee -a /etc/fstab echo "[4/6] Mounting drive..." sudo mount -a # === STEP 4: Move Docker data directory === echo "[5/6] Moving Docker data directory to USB drive..." if sudo systemctl is-active --quiet docker; then sudo systemctl stop docker fi if [ -d /var/lib/docker ]; then sudo mv /var/lib/docker $DOCKER_DIR sudo ln -s $DOCKER_DIR /var/lib/docker else echo "/var/lib/docker not found, skipping move." fi sudo systemctl start docker # === STEP 5: Clone IoTStack === echo "[6/6] Cloning IoTStack into $IOTSTACK_DIR..." if [ ! -d "$IOTSTACK_DIR" ]; then git clone https://github.com/SensorsIot/IOTstack.git $IOTSTACK_DIR else echo "IoTStack already exists in $IOTSTACK_DIR" fi echo "Setup complete! IoTStack is installed on the external drive." echo "To continue, run:" echo " cd $IOTSTACK_DIR" echo " ./menu.sh"
📦 How to Use the Script
- Save the script:
nano iotstack-usb-setup.shPaste the script and save (
Ctrl + O,Enter, thenCtrl + X)
- Make it executable:
chmod +x iotstack-usb-setup.sh
- Run it:
./iotstack-usb-setup.sh
✅ After the Script
Run the IoTStack menu:
cd /mnt/iotdata/IOTstack ./menu.shFrom here, you can select your Docker containers (like MQTT, Node-RED, InfluxDB, etc.)
Let me know if you want an advanced version with:
- BTRFS or exFAT support
- Remote backup setup
- Docker Compose migration
Or if you want a version that doesn’t format the drive.