on macOS, since Docker runs in a VM, using localhost does not work. However, containers can access services running on the host using the docker.for.mac.host.internal (since Docker 17.12.0-ce) or docker.for.mac.localhost (for previous versions of Docker). Thus, the container running the tests can connect to the database using such a hostname value and the published port of the container.