Skip to content
CodeKruPro

Read the Compose file: why chrome:4444 and not localhost?

QuizMediumAsked in: Capgemini, Swiggy

Read the Compose file.

docker-compose.yml

services:
  chrome:
    image: selenium/standalone-chrome:4.45.0
    shm_size: 2gb
    ports:
      - "4444:4444"
  tests:
    build: .
    depends_on:
      - chrome
    environment:
      SELENIUM_URL: http://chrome:4444

Why does the tests service use http://chrome:4444 instead of http://localhost:4444?

  • Inside the tests container, localhost is that container itself; Compose puts both services on one network where each is reachable by its service name
  • Selenium refuses connections from localhost
  • Port 4444 is only open for the host
  • It makes no difference

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in