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

  Work with me!


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 )

Thank you for reading! And see you soon on Strangebuzz! 😉

COil