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

Docker: Wait until ready #48

Open
LukeOwlclaw opened this issue Mar 17, 2022 · 2 comments
Open

Docker: Wait until ready #48

LukeOwlclaw opened this issue Mar 17, 2022 · 2 comments

Comments

@LukeOwlclaw
Copy link

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
Copy link

Re4zOon commented Aug 24, 2023

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants