[英]docker-compose healthcheck issue
I'm currently working on a microservice project using docker-compose.我目前正在使用 docker-compose 进行微服务项目。 So I was adding health checks to my containers.
所以我在我的容器中添加了健康检查。 But except mysql every thing else stays unhealthy but I don't know why.
但除了 mysql 之外,其他一切都保持不健康,但我不知道为什么。
Here is my docker-compose.yml file.这是我的 docker-compose.yml 文件。
version: "3"
services:
zookeeper:
image: wurstmeister/zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 52.78.52.254
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- zookeeper
mysql:
image: mysql
container_name: mysql
ports:
- "3306:3306"
volumes:
- ./data/mysql:/var/lib/mysql:rw
environment:
- MYSQL_ROOT_PASSWORD=dnjscksdn98@
- MYSQL_DATABASE=explanet_dev
- MYSQL_USER=alex
- MYSQL_PASSWORD=dnjscksdn98@
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "mysql", "-u$$MYSQL_USER", "-p$$MYSQL_ROOT_PASSWORD" ]
interval: 30s
timeout: 10s
retries: 3
api-gateway:
container_name: api-gateway
ports:
- "80:80"
build:
context: ./api-gateway
args:
ENVIRONMENT: dev
dockerfile: Dockerfile
healthcheck:
test: [ "CMD", "curl", "-f", "http://api-gateway/health-check" ]
interval: 30s
timeout: 10s
retries: 3
depends_on:
- mysql
chatting-service:
container_name: chatting-service
ports:
- "8080:8080"
build:
context: ./chatting-service
args:
ENVIRONMENT: dev
dockerfile: Dockerfile
healthcheck:
test: [ "CMD", "curl", "-f", "http://chatting-service:8080/health-check" ]
interval: 30s
timeout: 10s
retries: 3
depends_on:
- mysql
- kafka
- api-gateway
And if I type docker inspect ${any container name}
it shows like this in the State
.如果我输入
docker inspect ${any container name}
它在State
中显示如下。
"Health": {
"Status": "unhealthy",
"FailingStreak": 12,
"Log": [
{
"Start": "2020-12-01T04:47:28.090046668Z",
"End": "2020-12-01T04:47:28.158193366Z",
"ExitCode": -1,
"Output": "OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused \"exec: \\\"curl\\\": executable file not found in $PATH\": unknown"
},
{
"Start": "2020-12-01T04:47:58.162656864Z",
"End": "2020-12-01T04:47:58.233280387Z",
"ExitCode": -1,
"Output": "OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused \"exec: \\\"curl\\\": executable file not found in $PATH\": unknown"
},
{
"Start": "2020-12-01T04:48:28.238446336Z",
"End": "2020-12-01T04:48:28.325520772Z",
"ExitCode": -1,
"Output": "OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused \"exec: \\\"curl\\\": executable file not found in $PATH\": unknown"
},
{
"Start": "2020-12-01T04:48:58.330407168Z",
"End": "2020-12-01T04:48:58.398503364Z",
"ExitCode": -1,
"Output": "OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused \"exec: \\\"curl\\\": executable file not found in $PATH\": unknown"
},
{
"Start": "2020-12-01T04:49:28.403163576Z",
"End": "2020-12-01T04:49:28.477627297Z",
"ExitCode": -1,
"Output": "OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused \"exec: \\\"curl\\\": executable file not found in $PATH\": unknown"
}
]
}
My java Dockerfile looks like this.我的 java Dockerfile 看起来像这样。
FROM adoptopenjdk/openjdk11:alpine-jre
COPY build/libs/base-service-0.0.1-SNAPSHOT.jar base-service.jar
ARG ENVIRONMENT
ENV SPRING_PROFILES_ACTIVE=${ENVIRONMENT}
ENTRYPOINT ["java", "-jar", "base-service.jar"]
I'm currently running on Ubuntu 20.04 server.我目前正在 Ubuntu 20.04 服务器上运行。 Is there any solutions?
有什么解决办法吗?
Hello the error message is pretty clear, you can't run curl for health check because it's not included in base image you use, you need to install it.您好,错误信息很清楚,您无法运行 curl 进行健康检查,因为它不包含在您使用的基础映像中,您需要安装它。
Exemple for alpine images高山图像示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.