Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 3

How to connect to a Docker container?

Solved! Go to Solution.

As part of a GitHub action I would like to run a line like

docker run -d -p 4444:4444 --name selenium selenium/standalone-chrome

and then having it accessible to my application,

response = HTTP.post("$host:4444/wd/hub/session",
                     [("Content-Type" => "application/json")],
		     JSON3.write(Dict("desiredCapabilities" => wd.capabilities, wd.kw...)))

Currently, I get the following error using either

host = "localhost"

or

host = "host.docker.internal"

I have been looking at a few related posts (MySQL connection from Docker action?, Docker container not mapping to correct port - connection refused, Communicate from service BACK to job container), but haven't been able to figure out the exact changes to make it work. I have tried with the container name and network alias as well.

2 Replies
Solution
GitHub Staff
Message 2 of 3

Re: How to connect to a Docker container?

Hi, I replied in a different thread but will paste my comment here as well:

 

 ...

 

You could run the webdriver as a service container, in which case youd do something like:

 

services:
  selenium:
    image: selenium/standalone-chrome

 (see https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-...)

 

That way a docker network will be created, and from inside a container action, you can connect to it via the hostname "selenium" (comes from the service name). So youd just use hostname=selenium, port=4444

 

Note that in the above example, no port mapping were specified, thats because for user defined bridge networks in docker, all ports are accesible by default, so the application inside the container only needs to actually be listening on 4444

 

...

 

We dont currently support adding docker-specific options, like "network", when running container actions so unfortunately you wouldnt be able to create a network, and run your action attached to that network specifically (something like docker run --network ....)

 

Of course if you are using a javascript action that would be running on the host, so you could connect via localhost (if you ran the selenium container with --network host)

 

Hope that helps

Highlighted
Pilot Lvl 1
Message 3 of 3

Re: How to connect to a Docker container?

Thanks! That helped me better understand the service example-services.

I had some issues with the VM way, but the container one worked great. Here is my final workflow file.

name: CI

on: push

jobs:
  ci:
    container: node:current
    services:
      selenium: 
        image: selenium/standalone-chrome
        options: --health-cmd '/opt/bin/check-grid.sh'
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        julia-version: [1.3.0]
        julia-arch: [x64]
        os: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v1.0.0
      - uses: julia-actions/setup-julia@latest
        with:
          version: ${{ matrix.julia-version }}
      - uses: julia-actions/julia-buildpkg@latest
      - uses: julia-actions/julia-runtest@latest
      - uses: julia-actions/julia-uploadcodecov@latest
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      - uses: julia-actions/julia-docdeploy@releases/v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}