Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include a healthcheck binary for use in a docker compose environment #270

Closed
rgl opened this issue Mar 28, 2024 · 3 comments
Closed

include a healthcheck binary for use in a docker compose environment #270

rgl opened this issue Mar 28, 2024 · 3 comments
Labels
docker Docker builds and images enhancement New feature or request

Comments

@rgl
Copy link

rgl commented Mar 28, 2024

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.

@axllent
Copy link
Owner

axllent commented 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.

@axllent axllent added enhancement New feature or request docker Docker builds and images labels Mar 28, 2024
@axllent
Copy link
Owner

axllent commented 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?

@rgl
Copy link
Author

rgl commented Mar 30, 2024

It works as expected! Thank you!

@rgl rgl closed this as completed Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Docker builds and images enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants