compose: [BUG] docker compose up failing to connect to postgres container on Apple Silicon Macs
Description
Current Behavior
When running docker compose up
to set up a dev environment, my custom containers depend on a postgres
container. On most attempts of running docker compose up
, the custom containers fail to make a connection with postgres
, however there are occasions when it works. This issue is occuring for two out of three members of our team with Apple Silicon machines (M1 and M2), but it does not occur for the member of our team with an Intel Mac. We have already tried switching to the arm64v8/postgres
version of the postgres image but that has not fixed the issue.
version: '3'
services:
postgres:
image: postgres
environment:
- POSTGRES_USER=REDACTED
- POSTGRES_PASSWORD=REDACTED
- POSTGRES_DB=REDACTED
# volumes:
# - ./learn_prisma_default:/var/lib/docker/volumes/learn_prisma_postgres/_data
redis:
image: redis
env_file:
- .env
# My two custom containers
venture-copilot:
image: venture-copilot
ports:
- "8080:8080"
env_file:
- .env
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgres
- redis
dashboard:
image: dashboard
ports:
- "80:80"
env_file:
- .env
build:
context: dashboard
dockerfile: Dockerfile
depends_on:
- postgres
- redis
Here are the logs from a successful and failed example: https://gist.github.com/taimurshaikh/c497167b00c4bc06c05fded18ca9cd0e
Steps To Reproduce
No response
Compose Version
Docker Compose version v2.12.2
Docker Environment
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.9.1)
compose: Docker Compose (Docker Inc., v2.12.2)
dev: Docker Dev Environments (Docker Inc., v0.0.3)
extension: Manages Docker extensions (Docker Inc., v0.2.13)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.21.0)
WARNING: Plugin "/Users/taimurshaikh/.docker/cli-plugins/docker-init" is not valid: failed to fetch metadata: fork/exec /Users/taimurshaikh/.docker/cli-plugins/docker-init: no such file or directory
WARNING: Plugin "/Users/taimurshaikh/.docker/cli-plugins/docker-scout" is not valid: failed to fetch metadata: fork/exec /Users/taimurshaikh/.docker/cli-plugins/docker-scout: no such file or directory
Server:
Containers: 4
Running: 0
Paused: 0
Stopped: 4
Images: 4
Server Version: 20.10.21
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 1c90a442489720eec95342e1789ee8a5e1b9536f
runc version: v1.1.4-0-g5fd4c4d
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.15.49-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 7.667GiB
Name: docker-desktop
ID: 45IS:TCZX:YB3F:E5KM:ZGAU:SVYO:CEAW:YNSQ:IIPF:QYK4:5P2V:QIIT
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5000
127.0.0.0/8
Live Restore Enabled: false
Anything else?
List of things we have tried so far:
- Adding a healthcheck to the postgres container, experimenting with different timeout lengths and number of retries
- Upgrading Docker Desktop to latest version
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (8 by maintainers)
I’m getting the same error as previously mentioned. Docker is not creating the
postgres
container. It is just creating theapp
build. As myapp
depends on thepostgres
the build is failing every time.Here is my docker-compose file:
Here is the error I’m getting:
I’m facing a similar issue with random containers. Right now, I’m using Redis, MongoDB, RabbitMQ, MariaDB, and Postgres.
It randomly fails. According to my inspection, the main container is not being attached to the network of the Database and attaching correctly at others.
At my company we have this issue happening even with Linux Systems, so it should not be ann issue that happens only on Macs.
As I’ve mentioned the
service-one
orservice-two
randomly fails to connect to Redis, MariaDB, Postgres, or RabbitMQ. By inspection, the problem is occurring because sometimes the services are not connected to the right network.In my last error case, the
service-one
cannot connect toredis_api
andservice_two
connect. Additionally, both of them are connected torabbit_api
.