Docker and strategies to check database service availability

Marcio S Galli
1 min readJan 13, 2021

With a container-based infrastructure (Docker in this case) you will likely have separated containers — one for the database, another for your application, and perhaps another being a database administration container.

Problem — knowing when to connect to the database

Your application needs to know when the database is ready so that you can connect. In a prototype phase, you may think about starting up the database service before your application service. This idea may work if you can manually start each service — if you are manually waiting for it.

But as you move to the docker-compose (or another orchestration system), you will need to find another way to know when the database service is ready. This problem may not be so obvious for many because there are many application cases where the first database connection starts after the user does something using web views. Nevertheless, you may consider a “wait strategy” because there are many situations where you may need to start communicating with a database as soon as the services are up and running.

Solutions

Wait for strategy — by Docker

Wait for strategy in the example — by Digital Ocean

Discussion and architectures

  • Please add
  • ___

--

--