#Docker Compose MongoDB Setup

3 messages · Page 1 of 1 (latest)

austere axle
#

everythings work fine but the mongodb fails on startup everytime.

log:

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):

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"
quasi flax
#

and if you wonder i mount /data/keyfile then an init container check for a /data/keyfile/keyfile, if not present write it and perm/owner change, then the mongodb start with the --keyFile /data/keyfile/keyfile