pletcher

pletcher

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'

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

Marked As Solved

pletcher

pletcher

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

# Appended by flyctl
ENV ECTO_IPV6 true
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="0.0.0.0" -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 http://0.0.0.0:4000

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:

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

Other popular topics Top

New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement