Skip to content
Back

Docker Compose MongoDB Setup

  • 0
  • Self Hosted
  • Web
dennis
20 Apr, 2026, 15:31

everythings work fine but the mongodb fails on startup everytime.

log:

TypeScript
Generating random MongoDB keyfile...
/bin/bash: line 9: : No such file or directory

has something to do with this, but cannot really figure it out (from docs template):

TypeScript
entrypoint:
      - /bin/bash
      - -c
      - |
        set -e
        KEYFILE_PATH="/data/keyfile/mongo-keyfile"
        INIT_FLAG="/data/db/.mongodb_initialized"

        # Generate keyfile if it doesn't exist
        if [ ! -f "$KEYFILE_PATH" ]; then
          echo "Generating random MongoDB keyfile..."
          mkdir -p /data/keyfile
          openssl rand -base64 756 > "$KEYFILE_PATH"
        fi
        chmod 400 "$KEYFILE_PATH"
        chown mongodb:mongodb "$KEYFILE_PATH" 2>/dev/null || chown 999:999 "$KEYFILE_PATH"
TL;DR
Docker Compose MongoDB setup is failing on startup due to a missing directory for the MongoDB keyfile generation script. To fix this, ensure the directory structure is correct in the script and that the Docker volumes are properly mapped.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more