title: Test runner node cannot see selenium-hub. Getting Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
body: <p>In a nutshell, there is additional container as a test runner which cannot reach the selenium-hub. So, tests are failed.</p>
  <p>This container was added for running test on cloud by using cloud build.</p>
  <p>I created docker-compose as below:</p>
  <pre class="lang-yaml prettyprint-override"><code> version: &quot;3&quot;
      services:
        selenium-hub:
          image: selenium/hub:4.0.0-rc-1-prerelease-20210804
          container_name: selenium-hub
          ports:
            - &quot;4444:4444&quot;
          expose: 
            - 4444
      
        chrome:
          image: selenium/node-chrome:4.0.0-rc-1-prerelease-20210804
          shm_size: 2gb
          depends_on:
            - selenium-hub
          environment:
            - SE_EVENT_BUS_HOST=selenium-hub
            - SE_EVENT_BUS_PUBLISH_PORT=4442
            - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
          ports:
            - &quot;6900:5900&quot;
      
        chrome_video:
          image: selenium/video:ffmpeg-4.3.1-20210804
          volumes:
            - /Users/videos:/videos 
          depends_on:
            - chrome
          environment:
            - DISPLAY_CONTAINER_NAME=chrome
            - FILE_NAME=chrome_video.mp4
  </code></pre>
  <p>After containers start to work successfully, when I run <code>npm run test</code> for running selenium js tests, I got successful results and video recording in expected directory. But it should be automated as well. <code>npm run test</code> should be triggered somehow.</p>
  <p>In our CI/CD process, cloudbuild.yaml file is added for running on cloud.</p>
  <pre class="lang-yaml prettyprint-override"><code> steps:
     - name: 'docker/compose:1.29.2'
        args: ['run','test']
  
     - name: 'docker/compose:1.29.2'
        args: ['stop']
        timeout: 60s
  </code></pre>
  <p>Cloud build should trigger the new container below which is added to docker-compose file as test runner:</p>
  <pre class="lang-yaml prettyprint-override"><code>test:
      image:  node:16-alpine
      entrypoint:
      - sh
      - -c
      - |-
        cd /test
        npm install
        sleep 3
        npm run test
      volumes:
      - .:/test
      depends_on:
      - selenium
      network_mode: host
  </code></pre>
  <p>However with test container, tests are failed and get the error below:</p>
  <blockquote>
  <pre><code>24 packages are looking for funding
  
  
  run `npm fund` for details
  
  
  2 moderate severity vulnerabilities
  
  
  To address all issues, run:
  
  npm audit fix
  
  
  Run `npm audit` for details.
  
  
  &gt; js_mocha_selenium@1.0.0 test
  
  &gt; mocha test
  
  
  
  
  Preliminary steps for End to End Tests
  
  initalising the session...
  
  1) Login
  
  closing the session...
  
  2) &quot;after each&quot; hook for &quot;Login&quot;
  
  
  
  0 passing (108ms)
  
  2 failing
  
  
  1) Preliminary steps for End to End Tests
  
  Login:
  
  Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
  
  at ClientRequest.&lt;anonymous&gt; (node_modules/selenium-webdriver/http/index.js:273:15)
  
  at ClientRequest.emit (node:events:394:28)
  
  at Socket.socketErrorListener (node:_http_client:447:9)
  
  at Socket.emit (node:events:394:28)
  
  at emitErrorNT (node:internal/streams/destroy:157:8)
  
  at emitErrorCloseNT (node:internal/streams/destroy:122:3)
  
  at processTicksAndRejections (node:internal/process/task_queues:83:21)
  
  
  2) Preliminary steps for End to End Tests
  
  &quot;after each&quot; hook for &quot;Login&quot;:
  
  Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
  
  at ClientRequest.&lt;anonymous&gt; (node_modules/selenium-webdriver/http/index.js:273:15)
  
  at ClientRequest.emit (node:events:394:28)
  
  at Socket.socketErrorListener (node:_http_client:447:9)
  
  at Socket.emit (node:events:394:28)
  
  at emitErrorNT (node:internal/streams/destroy:157:8)
  
  at emitErrorCloseNT (node:internal/streams/destroy:122:3)
  
  at processTicksAndRejections (node:internal/process/task_queues:83:2
  </code></pre>
  </blockquote>
  <p>Containers:</p>
  <pre><code>CONTAINER ID   IMAGE                                                 COMMAND                   CREATED              STATUS              PORTS                                                      NAMES
  7ca30366bc09   node:16-alpine                                        &quot;sh -c 'cd /test\nnpm…&quot;   About a minute ago   Up About a minute                                                              e2e-tests_test_1
  fdf43be1b4da   selenium/video:ffmpeg-4.3.1-20210804                  &quot;/opt/bin/entry_poin…&quot;    16 minutes ago       Up About a minute   9000/tcp                                                   e2e-tests_chrome_video_1
  92c023b15cb6   selenium/node-chrome:4.0.0-rc-1-prerelease-20210804   &quot;/opt/bin/entry_poin…&quot;    16 minutes ago       Up About a minute   0.0.0.0:6900-&gt;5900/tcp, :::6900-&gt;5900/tcp                  e2e-tests_chrome_1
  86002f3d1eb9   selenium/hub:4.0.0-rc-1-prerelease-20210804           &quot;/opt/bin/entry_poin…&quot;    16 minutes ago       Up About a minute   4442-4443/tcp, 0.0.0.0:4444-&gt;4444/tcp, :::4444-&gt;4444/tcp   selenium-hub 
  </code></pre>
  <p>I can ping <strong>selenuim-hub</strong> from <strong>e2e-tests_test_1</strong> container, but cannot do it reverse(ping <strong>e2e-tests_test_1</strong> from <strong>selenium-hub</strong>).</p>
  <p>About current network:</p>
  <pre class="lang-json prettyprint-override"><code> &gt;&gt; % docker network inspect -v host
  [
      {
          &quot;Name&quot;: &quot;host&quot;,
          &quot;Id&quot;: &quot;36e4060f18be618399692294d10cf6be3478c1bf5190ea035b002ca87c18276b&quot;,
          &quot;Created&quot;: &quot;2021-06-30T10:36:33.170635189Z&quot;,
          &quot;Scope&quot;: &quot;local&quot;,
          &quot;Driver&quot;: &quot;host&quot;,
          &quot;EnableIPv6&quot;: false,
          &quot;IPAM&quot;: {
              &quot;Driver&quot;: &quot;default&quot;,
              &quot;Options&quot;: null,
              &quot;Config&quot;: []
          },
          &quot;Internal&quot;: false,
          &quot;Attachable&quot;: false,
          &quot;Ingress&quot;: false,
          &quot;ConfigFrom&quot;: {
              &quot;Network&quot;: &quot;&quot;
          },
          &quot;ConfigOnly&quot;: false,
          &quot;Containers&quot;: {},
          &quot;Options&quot;: {},
          &quot;Labels&quot;: {}
      }
  ]
  </code></pre>
  <p>It seems test node cannot reach to <strong>127.0.0.1:4444</strong></p>
  <p>What should I do for solving this issue?
  It'd be good to hear alternative solutions.</p>
  <p>Thanks in advance.</p>