Add dev init script with auto-created admin user (admin/admin) on first boot

This commit is contained in:
2026-06-16 17:52:46 +02:00
parent 427aedaae7
commit 83da1698c0
2 changed files with 40 additions and 4 deletions
+5 -4
View File
@@ -46,12 +46,13 @@ services:
MM_ANNOUNCEMENTSETTINGS_ADMINNOTICESENABLED: "false"
ports:
- "8065:8065"
# Auto-create admin user (admin/admin) on first boot.
entrypoint: ["/bin/bash", "/init.sh"]
volumes:
# Persistent plugin directory — mount the dist folder so you can
# upload plugins via UI or copy them directly:
# Init script creates admin user on first startup.
- ./init.sh:/init.sh:ro
# Plugin directory — mount so you can upload via UI:
- ./mattermost/plugins:/mattermost/data/plugins:rw
# Config override (optional — uncomment to persist config changes)
# - ./mattermost/config:/mattermost/config:rw
# Data volume for uploads, avatars, etc.
- mattermost-data:/mattermost/data:rw
healthcheck:
Executable
+35
View File
@@ -0,0 +1,35 @@
#!/bin/bash
# Mattermost init script — creates admin user on first boot.
# This is mounted into the container and replaces the default command.
set -e
# Start Mattermost server in the background.
/entrypoint.sh mattermost server &
MM_PID=$!
# Wait for the server to be ready.
echo "init: waiting for Mattermost to start..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8065/api/v4/system/ping > /dev/null 2>&1; then
echo "init: Mattermost is ready"
break
fi
if [ "$i" = "30" ]; then
echo "init: Mattermost failed to start within 60s"
exit 1
fi
sleep 2
done
# Create admin user (idempotent — ignores if already exists).
echo "init: creating admin user..."
/mattermost/bin/mattermost user create \
--email admin@example.com \
--username admin \
--password admin \
--system_admin 2>/dev/null && echo "init: admin user created" \
|| echo "init: admin user already exists (or creation skipped)"
# Bring Mattermost to the foreground.
wait $MM_PID