docker - docker-compose healthcheck for pentaho data integration (pdi)
问题描述
I am building my custom pdi image using docker. I could build image and ran it without any issues. Now I need to add healthcheck for my pdi container. Can anyone suggest me a healthcheck command?
I tried to use,
healthcheck:
test: /home/data-integration/kitchen.sh -file="/home/jobs/my.kjb" -level=Basic && echo $? || exit 1
but gives an error as,
ERROR: Invalid interpolation format for "healthcheck" option in service "pentaho": "/home/data-integration/kitchen.sh -file="/home/jobs/my.kjb" -level=Basic && echo $? || exit 1"
If I use healthcheck command as below it become unhealthy even there are no any errors.
healthcheck:
test: /home/data-integration/kitchen.sh -file="/home/jobs/my.kjb" -level=Basic || exit 1
if I find it from docker inspect containerID,
- I do not use carte or anything or any UIs. I just unzip the pdi zip file and want to run my pdi job to a given schedule. my entrypoint.sh file is as below,
#!/bin/sh
## entrypoint.sh
/home/data-integration/kitchen.sh -file="/home/jobs/my.kjb" -level=Basic
tail -f /dev/null
When I manually run job file and check echo $? it gives 0 as output if job is success. how to use it correctly in to docker-compose healthcheck?
解决方案
Being a new user, I cannot comment yet, so I hope this answer gives you something to think about.
Food for thought
Per the Docker documentation on healthchecks, the format is as stated: https://docs.docker.com/engine/reference/builder/#healthcheck
I'm not familiar with your application specifically, but if there is any startup required, then setting a delay to give the container time to initialize may be helpful.
I also see that you're using the same command in your entrypoint script that you are using to healthcheck.
Healthchecks should typically not be the same thing as the running process, and instead should be used to ensure the running process is working correctly. The docs highlight this, as does this blogpost, detailing how to check that a web app is alive by pinging the server.
Another note is that if your entrypoint tails dev null, you will not get the logs of the running process through docker logs
. If you want to schedule a task to run often in a container, I recommend wrapping your command in a while
loop which calls the command, or using an external orchestrator like Kubernetes Cron Jobs (Edit: Or even a crontab on the host that calls docker run
)
Fix
Finally, if you're set on simply fixing the immediate issue of formatting, you need to escape the $
character in the healthcheck, like so:
test: /home/data-integration/kitchen.sh -file="/home/jobs/my.kjb" -level=Basic && echo $$? || exit 1
Other issues akin to this are: How can I escape a $ dollar sign in a docker compose file?
And it links to the docs on variable escaping here: https://docs.docker.com/compose/compose-file/compose-file-v3/#variable-substitution
推荐阅读
- mongodb - 多个条件匹配的重复 MongoDB 响应
- javascript - 如何使用 Promise.all 方法?
- kubernetes - 启用 Kubernetes 服务的自动启动
- migration - 当在 IE11 中键入自动启动 Edge (Chromium) 时,什么“魔法”导致“cnn.com”?
- python - 如何将 Conll 2003 格式转换为 json 格式?
- apache-spark - 我们可以在批处理模式下使用 flatMapGroupsWithState 吗?
- php - 将较大的图像文件从 javascript XMLHttpRequest blob 上传到 php(保存的大小错误)
- kubernetes - 如何在 k8s 中获取服务的 ip/地址
- php - 在 WordPress 网站上通过电子邮件通知来宾作者
- c++ - C++ 模板能否提供 N 个给定类的公共父类?