MIT License

项目介绍

peter-evans/docker-compose-healthcheck 是一个托管在 GitHub 上的开源项目,采用 MIT License 许可证,目前获得 765 个 Star、59 次 Fork。

仓库全名
peter-evans/docker-compose-healthcheck
开源许可证
MIT License
Star 数
765
Fork 数
59
未关闭 Issue
6

README 摘要

The healthcheck property was originally introduced in the 2.1 Compose file format and is now part of the Compose Specification used by recent versions of Docker Compose. This allows a check to be configured in order to determine whether or not containers for a service are "healthy." How can I wait for container X before starting Y? This is a common problem and in earlier versions of docker-compose requires the use…

完整内容见 GitHub 原始 README 或本页 。

常见问题

docker-compose-healthcheck 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 docker-compose-healthcheck 的源码?

可以直接克隆仓库:git clone https://github.com/peter-evans/docker-compose-healthcheck.git,默认分支为 master;安装与运行步骤见仓库 README。

docker-compose-healthcheck 最近还在维护吗?

仓库最近一次更新为 2022年2月15日,当前有 6 个未关闭 Issue;Star 数为 765,可作为社区活跃度的参考。

关于

How to wait for container X before starting Y using docker-compose healthcheck

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
893
价值分
477
活跃状态
活跃

README

docker-compose-healthcheck The blog of Peter Evans: How to Wait for Container X Before Starting Y

Actions Status

The healthcheck property was originally introduced in the 2.1 Compose file format and is now part of the Compose Specification used by recent versions of Docker Compose. This allows a check to be configured in order to determine whether or not containers for a service are “healthy.”

How can I wait for container X before starting Y?

This is a common problem and in earlier versions of docker-compose requires the use of additional tools and scripts such as wait-for-it and dockerize. Using the healthcheck parameter the use of these additional tools and scripts is often no longer necessary.

Waiting for PostgreSQL to be “healthy”

A particularly common use case is a service that depends on a database, such as PostgreSQL. We can configure docker-compose to wait for the PostgreSQL container to startup and be ready to accept requests before continuing.

The following healthcheck has been configured to periodically check if PostgreSQL is ready using the pg_isready command. See the documentation for the pg_isready command here.

healthcheck:
  test: ["CMD-SHELL", "pg_isready"]
  interval: 10s
  timeout: 5s
  retries: 5

If the check is successful the container will be marked as healthy. Until then it will remain in an unhealthy state. For more details about the healthcheck parameters interval, timeout and retries see the documentation here.

Services that depend on PostgreSQL can then be configured with the depends_on parameter as follows:

depends_on:
  postgres-database:
    condition: service_healthy

Waiting for PostgreSQL before starting Kong

In this complete example docker-compose waits for the PostgreSQL service to be “healthy” before starting Kong, an open-source API gateway. It also waits for an additional ephemeral container to complete Kong’s database migration process.

Test it out with:

docker-compose up -d

Wait until all services are running:

Demo

Test by querying Kong’s admin endpoint:

curl http://localhost:8001/

License

MIT License - see the LICENSE file for details

评论

暂无评论