[GH-ISSUE #270] include a healthcheck binary for use in a docker compose environment #177

Closed
opened 2026-03-15 13:02:22 +03:00 by kerem · 3 comments
Owner

Originally created by @rgl on GitHub (Mar 28, 2024).
Original GitHub issue: https://github.com/axllent/mailpit/issues/270

in order to have a healthcheck in docker compose we need a command that returns a 0 exit code.

we either need a mailpit sub-command or an http client (e.g. curl) binary available inside the container.

for example, this docker compose file, uses curl (but a better approach would be to implement something equivalent of this example, but as a mailpit sub-command, e.g., mailpit readyz):

# see https://github.com/compose-spec/compose-spec/blob/master/spec.md
# see https://github.com/opencontainers/image-spec/blob/master/annotations.md
services:
  mailpit:
    # see https://hub.docker.com/r/axllent/mailpit
    # see https://github.com/axllent/mailpit
    # see https://mailpit.axllent.org/docs/install/docker/
    image: axllent/mailpit:v1.13.3
    command:
      - --smtp-auth-accept-any
      - --smtp-auth-allow-insecure
    ports:
      # smtp.
      # http://localhost:1025
      - 1025:1025
      # http.
      # http://localhost:8025
      - 8025:8025
    healthcheck:
      test: ["CMD", "curl", "--silent", "--fail-with-body", "--max-time", "5", "http://localhost:8025/readyz"]
      interval: 15s
      timeout: 5s
      retries: 2
    restart: on-failure

with this in place, we can use docker compose up --wait, to make it wait for all the containers/services within the docker compose environment to being healthy.

Originally created by @rgl on GitHub (Mar 28, 2024). Original GitHub issue: https://github.com/axllent/mailpit/issues/270 in order to have a healthcheck in docker compose we need a command that returns a 0 exit code. we either need a mailpit sub-command or an http client (e.g. `curl`) binary available inside the container. for example, this docker compose file, uses `curl` (but a better approach would be to implement something equivalent of this example, but as a mailpit sub-command, e.g., `mailpit readyz`): ```yaml # see https://github.com/compose-spec/compose-spec/blob/master/spec.md # see https://github.com/opencontainers/image-spec/blob/master/annotations.md services: mailpit: # see https://hub.docker.com/r/axllent/mailpit # see https://github.com/axllent/mailpit # see https://mailpit.axllent.org/docs/install/docker/ image: axllent/mailpit:v1.13.3 command: - --smtp-auth-accept-any - --smtp-auth-allow-insecure ports: # smtp. # http://localhost:1025 - 1025:1025 # http. # http://localhost:8025 - 8025:8025 healthcheck: test: ["CMD", "curl", "--silent", "--fail-with-body", "--max-time", "5", "http://localhost:8025/readyz"] interval: 15s timeout: 5s retries: 2 restart: on-failure ``` with this in place, we can use `docker compose up --wait`, to make it wait for all the containers/services within the docker compose environment to being healthy.
kerem 2026-03-15 13:02:22 +03:00
Author
Owner

@axllent commented on GitHub (Mar 28, 2024):

Thanks for the input @rgl, I'll look into this. The easiest solution would be to add curl to the Docker image - but I do see the benefits of a subcommand with a limited set of arguments, more specifically the listening interface & port (both as a commandline option and existing ENV variables). This way the docker image would only need to run mailpit ready (or similar) and return the exit status.

<!-- gh-comment-id:2024888115 --> @axllent commented on GitHub (Mar 28, 2024): Thanks for the input @rgl, I'll look into this. The easiest solution would be to add curl to the Docker image - but I do see the benefits of a subcommand with a limited set of arguments, more specifically the listening interface & port (both as a commandline option and existing ENV variables). This way the docker image would only need to run `mailpit ready` (or similar) and return the exit status.
Author
Owner

@axllent commented on GitHub (Mar 30, 2024):

This has been released in v1.15.1. I added a readyz subcommand which, in Docker, should auto-detect the port, webroot and HTTPS status of the running daemon. I also added this to the Dockerfile so you probably do not need to specify your own (unless you wish to use different defaults) 👍

Please confirm it works as you expect?

<!-- gh-comment-id:2028016975 --> @axllent commented on GitHub (Mar 30, 2024): This has been released in v1.15.1. I added a `readyz` subcommand which, in Docker, should auto-detect the port, webroot and HTTPS status of the running daemon. I also added this to the Dockerfile so you probably do not need to specify your own (unless you wish to use different defaults) :+1: Please confirm it works as you expect?
Author
Owner

@rgl commented on GitHub (Mar 30, 2024):

It works as expected! Thank you!

<!-- gh-comment-id:2028043176 --> @rgl commented on GitHub (Mar 30, 2024): It works as expected! Thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#177
No description provided.