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

feat: add health check command to the container #516

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pyrooka
Copy link

@pyrooka pyrooka commented Apr 30, 2024

Description

This PR adds a small improvement to the container, which utilises the Docker HEALTHCHECK command to report the inner state of the app to the Docker runtime. Basically, it runs the curl command periodically to check whether the webserver is up or not.

Motivation: I left a typo in my run.py file that I didn't notice and restarted the host around an hour later. That small issue led to a restart loop, but my Portainer instance reported Running - which in fact was true. I think if it would've had this health check, I could see the problem on the UI.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)

How Has This Been Tested?

I started a local container with the example run.py and when I inspected it, I could see the error logs:

{
	"Start": "2024-04-30T21:54:22.04317247Z",
	"End": "2024-04-30T21:54:22.126576887Z",
	"ExitCode": 1,
	"Output": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (7) Failed to connect to localhost port 5000 after 1 ms: Couldn't connect to server\n"
}

Running the same health check command in my "prod" container, returned exit code 0 which means everything is fine.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md)
  • My changes generate no new warnings
  • Any dependent changes have been updated in requirements.txt

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

None yet

1 participant