Hi all,
I’ve run into a wall with dockerizing a Phoenix. The application runs fine with mix phx.server
, but when I attempt to run it from a docker container, it won’t start up. (I’m on an M1 MacBook – but I can’t get a straight answer from Docker’s docks whether that even matters for this error.) Instead, it throws the following error:
ajmc-ajmc-reader-1 | Protocol 'inet6_tcp': register/listen error: eaddrnotavail
ajmc-ajmc-reader-1 exited with code 1
My compose.yaml currently looks like:
version: '3.5'
services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- 5432:5432
restart: unless-stopped
ajmc-reader:
build:
context: ./ajmc-multicommentary
dockerfile: Dockerfile
depends_on:
- postgres
environment:
DATABASE_URL: ${DATABASE_URL:-postgres://postgres:postgres@postgres:5432/ajmc_prod}
PHX_HOST: ${PHX_HOST:-0.0.0.0}
PORT: ${PORT:-4000}
volumes:
postgres:
The postgres
service starts fine, which leads me to believe that the issue is with my Phoenix app’s configuration.
My endpoint config in prod.exs currently looks like:
config :text_server, TextServerWeb.Endpoint,
http: [ip: {0, 0, 0, 0}, port: 4000],
url: [host: "localhost"]`
And in runtime.exs:
config :text_server, TextServerWeb.Endpoint,
url: [host: host, port: port],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
# ip: {0, 0, 0, 0, 0, 0, 0, 0},
ip: {0, 0, 0, 0},
port: port
],
secret_key_base: secret_key_base
I can’t get a stack trace from the error, so I’m not sure where the application is failing.
The application will start if I set network_mode: "host"
– but requiring raw access to the host’s network interfaces seems suboptimal.
Has anyone else encountered this? Could you point me in the right direction?
Thanks in advance!
(If it’s helpful, the application that I’m working on is a direct fork of GitHub - Open-Commentaries/open-commentaries: Open Commentaries is an online platform for sharing digital commentaries, editions, and translations. https://opencommentaries.org – which is currently running just fine on fly.io with essentially the same dockerfile.)