docker撰写健康检查不适用于neo4j docker



我有一个docker compose文件,它启动了几个容器。我想避开我目前看到的错误消息,这样其他docker容器只有在neo4j容器运行时才会启动。现在,我有:

version: '3.7'
services:
neo4j:
container_name: neo4j 
hostname: neo4j 
image: neo4j:3.5
restart: unless-stopped
environment:
- NEO4J_dbms_memory_pagecache_size=2G
- dbms_connector_bolt_tls__level=OPTIONAL
- NEO4J_dbms_memory_heap_max__size=3500M
- NEO4J_AUTH=neo4j/start
volumes:
- $HOME/neo4j/data:/data
- $HOME/neo4j/logs:/logs
- $HOME/neo4j/import:/import
- $HOME/neo4j/plugins:/plugins
ports:
- 7474:7474
- 7687:7687
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:7474/", "||", "exit 1"] 
interval: 10s
timeout: 2s
retries: 10
myapp:
container_name: myapp
hostname: myapp
image: python:3.7.3-slim
build: './APP'
restart: on-failure
environment:
- PYTHONUNBUFFERED=1 
ports:
- 5000:5000 

healthcheck参数没有区别。我还用过:

curl -i http://127.0.0.1:7474 2>&1 | grep -c -e '200 OK'  

而且。。。

["CMD-SHELL", "/var/lib/neo4j/bin/neo4j status"]

此刻,我的myapp试图加载,然后退出,直到neo4j运行。如何让myapp等到neo4j运行?

您确实在寻找depends_on,但只有在服务正常的情况下。这意味着docker compose文件必须如下所示:

version: "3.9"
services:
myapp:
...
depends_on:
# Make sure the application only starts when the DB is indeed ready
neo4j:
condition: service_healthy
neo4j:
...
healthcheck:
test: wget http://localhost:7474 || exit 1
interval: 1s
timeout: 10s
retries: 20
start_period: 3s

您正在查找depends_on注释。

关于您的特殊情况:

myapp:
...
depends_on: 
- "neo4j"

您可以在此处找到详细信息:https://docs.docker.com/compose/startup-order/

最新更新