Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 9

MySQL connection from Docker action?

Solved! Go to Solution.


can I somehow pass a service (specifically a database connection) to a Docker action?


When I try to pass options like this:

    database_user: myUser
    database_port: "${{['3306'] }}"

and use this information inside my file

I get the following error:

mysql -h --port 32768 -u myUser -pxy -e "CREATE DATABASE IF NOT EXISTS myDB;"

ERROR 2002 (HY000): Can't connect to MySQL server on '' (115)

Is there any possibility to map the connection? Or do I need to setup MySQL inside my Docker container?


Thanks for your advice,



8 Replies
GitHub Partner
Message 2 of 9

Re: MySQL connection from Docker action?

There are some of the possible causes of this error:

1) Network failure especially if mysql database server is running on remote host.

2) No mysql server is running on the mentioned host.

3) Firewall blocking TCP-IP connection or other related reasons.


You can try using ping command to test the client-server connectivity, such as “ping”.

The following are two Docker container actions for MySQL and docs for MySQL image, maybe you can reference them:

Setup MySQL

Start MySQL

Copilot Lvl 3
Message 3 of 9

Re: MySQL connection from Docker action?

I already have a MySQL server setup like this:

        image: mysql:5.7
          MYSQL_USER: myUser
          MYSQL_PASSWORD: myPass
          MYSQL_DATABASE: myDB
          MYSQL_ROOT_PASSWORD: myPass
          - 3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

But my special use case is that I do not want to use it directly in the workflow, but within a docker action used by the workflow. I will try to use the default mysql available in virtual environments instead.

Copilot Lvl 3
Message 4 of 9

Re: MySQL connection from Docker action?

This thread at stack overflow contains several possible solutions:


Is it possible with GitHub actions to call a docker image in host mode by setting/appending

--network=host or --net=host



GitHub Staff
Message 5 of 9

Re: MySQL connection from Docker action?

All containers (job, service, actions) get attached to the same user defined bridge network on the host, meaning all the containers can reach each other over that network, not via the host's localhost networking. From inside your action, you should be able to connect to mysql with hostname mysql (comes from the name of your service) and the default port 

Copilot Lvl 3
Message 6 of 9

Re: MySQL connection from Docker action?

Thank you very much! I'd never found this by myself.

Pilot Lvl 1
Message 7 of 9

Re: MySQL connection from Docker action?

If I wanted to connect to a remote webdriver from inside a GitHub Action,

after running

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

what address should I use rather than 

GitHub Staff
Message 8 of 9

Re: MySQL connection from Docker action?

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


    image: selenium/standalone-chrome



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

Copilot Lvl 3
Message 9 of 9

Re: MySQL connection from Docker action?

What if we have a custom docker container and cannot run it as a service? How can we connect to it?

docker run -d -p 8378:8378 customcontainer:$GITHUB_SHA
curl --retry 10 --retry-delay 5 --retry-connrefused -v http://localhost:8378