diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 8de6fac..ca41426 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -5,9 +5,9 @@ services: ports: - '80:80' - '443:443' - environment: - # Bare-IP access only. - # DEFAULT_HOST: 'bot.example.com' + # Bare-IP access only. Uncomment to enable. + # environment: + # DEFAULT_HOST: 'bot.example.com' volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./nginx-certs:/etc/nginx/certs:ro diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 6e6450b..19e0ae3 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,9 +5,21 @@ if [ "$(id -u)" -eq '0' ] then USER_ID=${LOCAL_USER_ID:-9001} - useradd --shell /bin/bash -u ${USER_ID} -o -c "" -m user > /dev/null 2>&1 - usermod -a -G root user > /dev/null 2>&1 - chown -R `id -u user`:`id -u user` /app > /dev/null 2>&1 + # `docker compose restart` / `docker restart` reuse the same container, so + # the overlay fs keeps the user created on first boot. A second `useradd` + # then fails with exit code 9, which would trip `set -e` and kill the + # container on every restart. Create only if missing; align the UID + # otherwise so LOCAL_USER_ID changes still apply. + if ! id user > /dev/null 2>&1 + then + useradd --shell /bin/bash -u ${USER_ID} -o -c "" -m user > /dev/null 2>&1 || true + else + usermod -u ${USER_ID} -o user > /dev/null 2>&1 || true + fi + usermod -a -G root user > /dev/null 2>&1 || true + # Bind-mounted volumes may not support chown; a failure here must not kill + # the container either. + chown -R `id -u user`:`id -u user` /app > /dev/null 2>&1 || true export HOME=/home/user # setpriv (util-linux, present in bookworm-slim) replaces gosu: drop to the