version: \'3\'
services:
server:
container_name: hotel-server
build:
dockerfile: Dockerfiles/server/Dockerfile
context: .
environment:
dbhost: db
l
Is there any workaround to that?
Yes.
First, realize that depends-on
is almost entirely useless. Docker doesn't know anything about your application; it has no way to tell that your database server isn't actually ready to service requests.
The correct solution is to code your application so that (a) it will retry the initial database connection until it is ready, and (b) it will reconnect to the database if the connection should fail. (a) solves the problem you're asking about, and (b) allows you to restart the database container independent of the application container.
If you don't control the code in your application container, you can wrap your main command with a shell script that does something like:
while ! psql -c 'select 1'; do
sleep 1
done
(Setting appropriate authentication options or setting up a .pgpass
file)