From d06cdced370d63bf31dd3f0d09432edc646b8b36 Mon Sep 17 00:00:00 2001 From: HardMax71 Date: Tue, 3 Mar 2026 20:19:09 +0100 Subject: [PATCH] fix: use container-internal env vars in mongo healthcheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mongosh 2.6.0 + MongoDB 8.0 produces "storedKey mismatch" when the connection URI includes a database path (localhost/integr8scode) while --authenticationDatabase points to a different db (admin). Switching to explicit --host/--port flags with --username/--password avoids this. Also replaces ${MONGO_PASSWORD:-...} host-side interpolation (which mangles passwords containing $, `, " via the container's sh) with $$MONGO_INITDB_ROOT_USERNAME / $$MONGO_INITDB_ROOT_PASSWORD — the $$ escape tells docker-compose to emit a literal $ so the container shell expands the variables from the mongo container's own environment, where they are already set by the environment: block. Co-Authored-By: Claude Sonnet 4.6 --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index b53cea8e..e033c209 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -60,7 +60,7 @@ services: soft: 65536 hard: 65536 healthcheck: - test: echo 'db.runCommand("ping").ok' | mongosh localhost/integr8scode -u ${MONGO_USER:-root} -p ${MONGO_PASSWORD:-rootpassword} --authenticationDatabase admin --quiet + test: mongosh --quiet --host 127.0.0.1 --port 27017 --username $$MONGO_INITDB_ROOT_USERNAME --password $$MONGO_INITDB_ROOT_PASSWORD --authenticationDatabase admin --eval 'db.adminCommand("ping")' interval: 3s timeout: 5s retries: 15