gessnerfl / fake-smtp-server

A simple SMTP Server for Testing purposes. Emails are stored in an in-memory database and rendered in a Web UI
Apache License 2.0
422 stars 88 forks source link

Docker: Wait until ready #48

Open LukeOwlclaw opened 2 years ago

LukeOwlclaw commented 2 years ago

I am using fake-smtp-server with docker-compose for development. I noticed that it takes some time until port 5080 is actually ready to serve connections.

What do you think about including wait-for-it.sh in the Dockerfile?

For a quick howto, see: https://selahattinunlu.medium.com/how-to-wait-for-a-container-to-be-ready-757bc1a86468

Re4zOon commented 1 year ago

Hi there,

From compose v3 you can implement a healthcheck. I haven't looked at the image, but if curl is available, you can do something like:

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:5080"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s

I dont know which one is port 5080 for you (SMTP/HTTP), but: SMTP gives back rc 1 HTTP gives back rc 22 (as its 404) Unavailable port gives back rc 7

With this in mind, you can setup a healthcheck one-liner. For example:

healthcheck:
  test: ["CMD", "curl -f localhost:8081 > /dev/null 2>&1; if [[ $? -eq 22 ]]; then exit 0; else exit 1; fi"]
  interval: 1m30s
  timeout: 10s
  retries: 3
  start_period: 40s

https://docs.docker.com/compose/compose-file/compose-file-v3/#healthcheck

gessnerfl commented 1 year ago

@Re4zOon thank you for sharing. I agree that this is a valid alternative.