Testing if a Docker container is healthy in a Makefile
Published on 2021-02-27 • Modified on 2021-02-27
In this snippet, we will see how to test if a Docker container is healthy in a Makefile. The goal is to use this check before running the tests, for example. They will fail if the database container is not up and ready to be used.
test: phpunit.xml check ## Run main functional and unit tests
check: ## Docker check
@$(DOCKER) info > /dev/null 2>&1 # Docker is up
@test '"healthy"' = `$(DOCKER) inspect --format "{{json .State.Health.Status }}" strangebuzz-db-1` # Db container is up and healthy
More on Stackoverflow Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉