mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
fix: make docker entrypoint restart-safe
docker compose restart reuses the container, so the overlay fs keeps the user created on first boot; a second useradd fails with exit code 9 and set -e kills the container on every restart (crash loop, bot never comes back). Create the user only if missing, align UID otherwise, and never let chown failure on bind-mounted volumes kill the container. Also comment out nginx-proxy's empty environment block in the compose example: an empty mapping fails validation on newer compose versions (must be a mapping).
This commit is contained in:
@@ -5,9 +5,9 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- '80:80'
|
||||||
- '443:443'
|
- '443:443'
|
||||||
environment:
|
# Bare-IP access only. Uncomment to enable.
|
||||||
# Bare-IP access only.
|
# environment:
|
||||||
# DEFAULT_HOST: 'bot.example.com'
|
# DEFAULT_HOST: 'bot.example.com'
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
- ./nginx-certs:/etc/nginx/certs:ro
|
- ./nginx-certs:/etc/nginx/certs:ro
|
||||||
|
|||||||
+15
-3
@@ -5,9 +5,21 @@ if [ "$(id -u)" -eq '0' ]
|
|||||||
then
|
then
|
||||||
USER_ID=${LOCAL_USER_ID:-9001}
|
USER_ID=${LOCAL_USER_ID:-9001}
|
||||||
|
|
||||||
useradd --shell /bin/bash -u ${USER_ID} -o -c "" -m user > /dev/null 2>&1
|
# `docker compose restart` / `docker restart` reuse the same container, so
|
||||||
usermod -a -G root user > /dev/null 2>&1
|
# the overlay fs keeps the user created on first boot. A second `useradd`
|
||||||
chown -R `id -u user`:`id -u user` /app > /dev/null 2>&1
|
# 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
|
export HOME=/home/user
|
||||||
# setpriv (util-linux, present in bookworm-slim) replaces gosu: drop to the
|
# setpriv (util-linux, present in bookworm-slim) replaces gosu: drop to the
|
||||||
|
|||||||
Reference in New Issue
Block a user