After a fair bit of false starts, computer crashes, and me not actually know what I was doing (Linux noob, on Kubuntu), I’ve managed to throw together a Bash script that makes my life easier in testing the Docker container options for Web Things. Let me know if it can be improved and made better.
#!/usr/bin/env bash
set -euo pipefail
#---- config ----
CONTAINER_NAME="webthings-gateway"
IMAGE="webthingsio/gateway:2.1.0-beta.2"
DATA_DIR="/opt/webthings-gateway/data" # bind mount on the host, persists across container recreation
TZ_VALUE="Australia/Melbourne"
#---- prep ----
mkdir -p "$DATA_DIR"
#---- idempotency: remove any existing container with this name ----
if docker container inspect "$CONTAINER_NAME" >/dev/null 2>&1; then
echo "Removing existing container: $CONTAINER_NAME"
docker rm -f "$CONTAINER_NAME"
fi
#---- run ----
docker run -d
--name "$CONTAINER_NAME"
--restart unless-stopped
-e TZ="$TZ_VALUE"
-v "$DATA_DIR":/home/node/.webthings
--network=host
--log-opt max-size=1m
--log-opt max-file=10
"$IMAGE"
echo "Started $CONTAINER_NAME from $IMAGE"