A container being started does not mean it is ready to accept connections. Docker marks the container as running the moment the entrypoint process starts. PostgreSQL needs another second or two to initialize storage, bind to port 5432, and start accepting connections. If your test code tries to connect before the database is ready, you get Connection refused. The wrong solution is Thread.sleep(5000). That is a fixed delay: too short on a slow machine, too long on a fast one.
Continue reading »Wait-Strategy
1 post in this section