Docker Compose networking non-deterministically failing with postgres + prisma

I’ve run into an issue where running migrations using the prisma framework, in an application container, against a postgres container, both in docker compose.

Running these migrations works ~10% of the time from within docker, failing non-deterministically with what looks like network errors, and works 100% of the time when running outside of docker against the db’s exposed port.

I’ve included a repo which you can pull. It includes instructions to reproduce (assuming a similar env).

Does anyone know what might be going on?

Thank you


  • macOS: Monterey 12.6.2
  • docker 20.10.22
  • docker desktop 4.16.2

I’m also seeing the following errors in my logs,

2023-02-02 19:41:21.958421-0800  localhost com.docker.backend[25903]: (47d02d51) 864cb1da-BackendAPI S<-C b3fc8d54-DriverCMD POST /usage[[STACK]]*backendClient).UpdateUsage(0x140004d3810, {{0x140005aeae0, 0x16}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, 0x1}) +0xbc*BackendAnalytics).sendCommand(0x14000536480, {0x104c4c2cf, 0xe}, {0x104c42675, 0x3}, 0x1) +0xb4*BackendAnalytics).trackRouteForHTTPMethod(0x14000504978?, 0x1400064ac00, 0x104f50818?, 0x104f45f60) +0xc8*BackendAnalytics).Middleware.func1({0x104f4fe38, 0x140001a0460}, 0x1400064ac00) +0xa8*Router).ServeHTTP(0x14000140180, {0x104f4fe38, 0x140001a0460}, 0x1400064a700)
	gith<decode: missing data>
2023-02-02 19:41:21.958458-0800  localhost com.docker.backend[25903]: [...] +0x19c

Is this the error message that looks like a network issue?

I can’t recognize it. How much time these migrations take?

The logs are probably unrelated to the issues I’m seeing. The migrations are small and fast, and should take < 1 second. All they’re doing is running this sql command, effectively.

The linked repo includes network failure error logs.

Your config looks good to me. I could imagine an unlikely scenario where you attach other compose projects to the network of this one and at least one of them contains a service or container called “postgres” so using the hostname “postgres” would randomly point to a wrong Postgres database that doesn’t accept request on the excpected port.

I don’t think you did that, so I don’t know why the migration would not work. I don’t know Prisma, so if it is related to that, I can’t tell you.