Web Things Gateway 2.1, A Possibly Better Bash Script for Docker

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"

This is a totally reasonable approach, but I would also suggest exploring the use of docker compose to move a lot of this configuration into a more friendly YAML-based configuration file, there is an example at:

You can then easily download and start the gateway image with a single command:

$ sudo docker compose up -d

Hi Ben.

Thanks for the information. Now I have two options to play with.

Unfortunately, network access has now decided to jump ship. Working on it whilst I learn Docker.

Cheers.