Phoenix app won't start in docker container -- fails with `Protocol 'inet6_tcp': register/listen error: eaddrnotavail`

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'

    image: postgres:15
      PGDATA: /data/postgres
      - postgres:/data/postgres
      - 5432:5432
    restart: unless-stopped

      context: ./ajmc-multicommentary
      dockerfile: Dockerfile
      - postgres
      DATABASE_URL: ${DATABASE_URL:-postgres://postgres:postgres@postgres:5432/ajmc_prod}
      PHX_HOST: ${PHX_HOST:-}
      PORT: ${PORT:-4000}


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
      # 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. – which is currently running just fine on with essentially the same dockerfile.)

Well, I feel kind of dumb. I had completely missed what appended ages ago to the dockerfile:

# Appended by flyctl
ENV ERL_AFLAGS "-proto_dist inet6_tcp"

And Docker Desktop doesn’t support IPv6.

Removing those lines, I can build and run the docker container just fine.

$ docker run --rm -e PHX_HOST="" -e PORT="4000" -e DATABASE_URL="postgres://{localpostgres}:5432/phoenix_app_dev" -e SECRET_KEY_BASE="very_long_test_secret_key" -it ajmc-reader
14:06:04.145 [info] Running TextServerWeb.Endpoint with cowboy 2.10.0 at :::4000 (http)
14:06:04.145 [info] Access TextServerWeb.Endpoint at

I’ll leave this here in case anyone else runs across this kind of issue in the future. Thank you, Elixir Forms and all, for being my rubber duck. :duck: