# Ping endpoint working but docker healthcheck fails

**URL:** <https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845>\
**Category:** Traefik v2\
**Tags:** ping, docker\
**Created:** [February 24, 2021, 9:00pm UTC](https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845 "2021-02-24T21:00:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonnyBeeGod](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jonnybeegod/32/3448_2.png) [@JonnyBeeGod](https://community.traefik.io/u/JonnyBeeGod)\
**Post date:** [February 24, 2021, 9:00pm UTC](https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845/1 "2021-02-24T21:00:42Z")

</div>

My docker-compose.yml contains this:

```auto
services:
  traefik:
    image: "traefik:v2.4"
    container_name: "traefik"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=traefik-public
        - traefik.constraint-label=traefik-public
        # ping
        - traefik.http.routers.ping.rule=Host(`traefik.domain.com`) && Path(`/ping`)
        - traefik.http.routers.ping.service=ping@internal
        - traefik.http.routers.ping.tls.certresolver=le
        - traefik.http.routers.ping.tls=true
        [...]
    command:
      [...]
      - --ping=true
      - --ping.entrypoint=websecure
      - --ping.manualRouting=true

```

This successfully exposes the ping endpoint under [https://traefik.domain.com/ping](https://traefik.domain.com/ping)

Now if I want to implement automatic health checks via docker, the container always fail to deploy.  
I tried it by adding the healthcheck directive to the docker-compose file:

```auto
healthcheck:
  test: ["CMD", "traefik", "healthcheck", "--ping"]
  interval: 30s
  timeout: 3s
  retries: 30

```

Any ideas? Do I need to somehow tell the healthcheck command the path / subdomain where to reach ping endpoint?

---

<div class="post-metadata">

**Author:** ![jakubhajek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jakubhajek/32/3389_2.png) [@jakubhajek](https://community.traefik.io/u/jakubhajek)\
**Post date:** [February 25, 2021, 9:12am UTC](https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845/2 "2021-02-25T09:12:18Z")

</div>

hey,  
please have a look on the recommended health check command. You can update the domain that points to Traefik instance and tune other parameters (internal, start\_period) according to your needs.

```auto
 healthcheck:
      test: wget --quiet --tries=1 --spider http://ping.127.0.0.1.nip.io/ping || exit 1
      interval: 10s
      timeout: 1s
      retries: 3
      start_period: 10s

```

More details in that repo:

> <https://github.com/jakubhajek/traefik-proxy/blob/fd0deb41f79068657472c1f68a4e1d75cd809c34/basic-docker-swarm/traefik-stack.yaml#L8>

---

<div class="post-metadata">

**Author:** ![JonnyBeeGod](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jonnybeegod/32/3448_2.png) [@JonnyBeeGod](https://community.traefik.io/u/JonnyBeeGod)\
**Post date:** [February 26, 2021, 6:26am UTC](https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845/3 "2021-02-26T06:26:14Z")

</div>

Thank you very much this works! Although I think this should be mentioned in the documentation as it suggests to use the CLI healthcheck command for healthchecks. [Ping - Traefik](https://doc.traefik.io/traefik/operations/ping/#configuration-options)

---

<div class="post-metadata">

**Author:** ![jakubhajek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jakubhajek/32/3389_2.png) [@jakubhajek](https://community.traefik.io/u/jakubhajek)\
**Post date:** [February 26, 2021, 8:25am UTC](https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845/4 "2021-02-26T08:25:00Z")

</div>

Glad to hear that it solved your issue. Thanks a lot for your feedback, we will update the documentation accordingly by adding examples of how to implement healthcheck correctly on K8S and Swarm 🙂  
👋

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [March 1, 2021, 8:25am UTC](https://community.traefik.io/t/ping-endpoint-working-but-docker-healthcheck-fails/9845/5 "2021-03-01T08:25:41Z")

</div>

Closed on March 1, 2021, 8:25am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
