Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain resolves on host machine but not inside docker container

I have two containers, one running a Node.js process that launches protractor, and another running a standalone Selenium container. The file looks like this:

version: '2'

services:
  www.example.localhost:
    build: .
    depends_on:
      - selenium
    dns_search:
      - static.example.localhost
    extra_hosts:
      - "static.example.localhost:127.0.0.1"
    ports:
      - "3000:3000"
      - "4000:4000"
    volumes:
      - ./src:/code/src
      - ./api:/code/api
    entrypoint: "npm run"
    command: "test:e2e"

  selenium:
    dns_search:
      - selenium.example.localhost
    image: selenium/standalone-chrome-debug:2.52.0
    environment:
      no_proxy: localhost
    volumes:
      - /dev/urandom:/dev/random
    ports:
      - "4444:4444"
      - "6900:5900"

www.example.localhost runs protractor, which in turn connects to the selenium container with these lines in protractor.config.js:

seleniumAddress: "http://selenium:4444/wd/hub",
directConnect: false,

When I run VNC on the selenium container, open up the chrome browser inside the container and type www.example.localhost:3000 it fails to resolve the domain. However when I run wget www.example.localhost:3000 it gets the index.html file just fine. Any idea what I'm doing wrong?

like image 536
James Hush Avatar asked Dec 08 '25 06:12

James Hush


1 Answers

Turns out in Google Chrome, any domain ending in localhost resolves to 127.0.0.1, no matter what DNS settings you have. Changing the domain from .localhost to .dev fixes it.

like image 178
James Hush Avatar answered Dec 09 '25 18:12

James Hush