aidalgol

aidalgol

Host lookup failure with Hound and Selenium under docker-compose

I am trying to add end-to-end testing with Hound and Selenium to my Phoenix application that is run under docker-compose, and I keep getting could not create a new session: timeout, check webdriver is running from Hound, even though I am invoking mix through a wrapper script that first waits until Selenium is ready. I cannot figure out why the Selenium status check passes and then Hound fails to connect, because they are both set to point to the same hostname and port.

docker-compose.yml

version: "3.3"
services:
  phoenix:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - 4000:4000
      - 4001:4001
      - 4002:4002
    depends_on:
      - db
      - selenium
    environment:
      - POSTGRES_HOST=db
    volumes:
      - .:/paddy

  db:
    image: postgres:11
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - "${DB_PORT}:5432"
    volumes:
      - "${HOME}/srv/paddy-db:/var/lib/postgresql/data"

  selenium:
    image: selenium/standalone-firefox:4
    ports:
      - 4444:4444
      - 7900:7900
    volumes:
      - /dev/shm:/dev/shm

Entrypoint script for the phoenix service:

#!/bin/bash

echo 'Waiting for database to be ready...'
while ! pg_isready -q -h "$POSTGRES_HOST" -p 5432 -U postgres; do
  sleep 2
done

echo 'Waiting for Selenium to be ready...'
while ! [ "$(curl -sSL http://selenium:4444/status | jq -r '.value.ready')" == "true" ]; do
  sleep 2
done

exec mix "$@"

Relevant parts of config/test.exs

config :paddy, PaddyWeb.Endpoint,
  http: [port: 4002],
  server: true

config :hound,
  driver: "selenium",
  host: "http://selenium",
  port: 4444,
  browser: "firefox",
  app_host: "http://phoenix",
  app_port: 4002

Hound error:

21:43:29.785 [error] GenServer Hound.SessionServer terminating
** (RuntimeError) could not create a new session: timeout, check webdriver is running
    (hound 1.1.1) lib/hound/session_server.ex:101: Hound.SessionServer.create_session/2
    (hound 1.1.1) lib/hound/session_server.ex:78: Hound.SessionServer.handle_call/3
    (stdlib 3.12.1) gen_server.erl:661: :gen_server.try_handle_call/4
    (stdlib 3.12.1) gen_server.erl:690: :gen_server.handle_msg/6
    (stdlib 3.12.1) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.853.0>): {:change_session, #PID<0.853.0>, :default, []}

Update:
This error seems to happen when I rerun docker-compose too soon after the previous run. If I wait a little bit longer, it gives me this instead:

     ** (RuntimeError) Reached error page: about:neterror?e=dnsNotFound&u=http%3A//phoenix%3A4002/&c=UTF-8&d=We%20can%E2%80%99t%20connect%20to%20the%20server%20at%20phoenix.
     Build info: version: '4.0.0-beta-4', revision: 'a51085a604'
     System info: host: '254bef88f074', ip: '172.18.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.0-0.bpo.5-amd64', java.version: '11.0.11'
     Driver info: driver.version: unknown

So it looks like Firefox is unable to resolve the hostname of the phoenix service/container.

First Post!

antondomratchev

antondomratchev

Hello,

I have the same issue. I am only able to make it work if I explicitly specify the ip address of the container.

test.exs

config :hound,
  driver: "selenium",
  host: "http://selenium",
  port: 4444,
  browser: "chrome",
  app_host: "http://172.18.0.5",
  app_port: 4001

docker-compose.yml

web:
    build: ./docker/web
    depends_on:
      - db
      - redis
      - selenium
    environment:
      MIX_ENV: dev
    env_file:
      - .env
    ports:
      - '4000:4000'
    volumes:
      - .:/app
  selenium:
    image: 'selenium/standalone-chrome:4.1.2-20220131'
    ports:
      - 4444:4444
      - 7900:7900
    shm_size: 2g
    cap_add:
      - 'SYS_ADMIN'
    volumes:
      - '.:/home/seluser/files'

Have you been able to resolve this issue with hostname resolution on selenium ?

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement