Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mongo/Dockerfile → mongo/Dockerfile.4.4
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mongo
FROM mongo:4.4

COPY docker-healthcheck /usr/local/bin/

Expand Down
5 changes: 5 additions & 0 deletions mongo/Dockerfile.5.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mongo:5.0

COPY docker-healthcheck /usr/local/bin/

HEALTHCHECK CMD ["docker-healthcheck"]
5 changes: 5 additions & 0 deletions mongo/Dockerfile.latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mongo:latest

COPY docker-healthcheck /usr/local/bin/

HEALTHCHECK CMD ["docker-healthcheck"]
15 changes: 12 additions & 3 deletions mongo/docker-healthcheck
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ set -eo pipefail

host="$(hostname --ip-address || echo '127.0.0.1')"

if mongo --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
exit 0
fi
# mongo for version <= 4.4
# mongosh for version >= 5.0
for cmd in mongosh mongo; do
if ! command -v "$cmd" > /dev/null; then
continue;
fi

if "$cmd" --quiet "$host/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'; then
exit 0
fi

done

exit 1