1.正确的打开方式
由于healthcheck执行的指令是在容器内部执行的,而docker-neo4j内部并没有curl指令,所以我们不能通过curl -f localhost:7474 || exit 1
这样的指令来去判断neo4j容器是否运行正常,这样得到的结果总是unhealthy。
正确的打开方式应该是:
healthcheck:
test: ["CMD-SHELL", "echo 'match (n) return count(n);' | bin/cypher-shell -a bolt://localhost:7687 -u neo4j -p xxx || exit 1"]
对于选择授权的neo4j容器而言,需要指定上面的用户名和密码。
2.参考
- How to Implement Docker Health Checks | by Nassos Michas | Better Programming | Medium
- Cypher Shell - Operations Manual
- Neo4j : How do I authenticate with cypher-shell without specifying the username and password on the command line - Neo4j Graph Database Platform
- Unable to probe health when composing · Issue #114 · neo4j/docker-neo4j