runner icon indicating copy to clipboard operation
runner copied to clipboard

Docker run - service mysql Connection Refused from CI

Open christrt9 opened this issue 2 years ago • 3 comments

We have Github self runner latest version with container install. It create a service mysql database in container.

We are testing some Github Runners but we get error Connection Refused when we run one command from CI. And before that command we run mysql command and it can connect with success. When i put sleep in CI and connect to container and run manually the command is success. I add some print command to show me the connection and is the correct one.

The init database it finish with success, it failed to php artisan app:prepare -vvv

jobs:
  test:
    runs-on: [self-hosted, test]
    services:
      mysql:
        image: mysql:8.0.23
        env:
          MYSQL_USER: test
          MYSQL_ROOT_PASSWORD: test
        ports:
          - 3306
     steps:
      - uses: actions/checkout@v1
        with:
          fetch-depth: 1

     - name: Get the mysql host
        id: get_host
        run: |
          host=`docker network inspect -f '{{(index .IPAM.Config 0).Gateway}}' bridge`
          echo "db-host=$host" >> $GITHUB_OUTPUT

      - name: Init Database
        run: |
          host=`docker network inspect -f '{{(index .IPAM.Config 0).Gateway}}' bridge`
          mysql -uroot --password=test -h ${{ steps.get_host.outputs.db-host }} --port ${{ job.services.mysql.ports['3306'] }} -e "SET GLOBAL sql_mode = ''"

   - name: PHP artisan command
        run: | 
            cp -a .env.ci .env
            sed -i 's/127.0.0.1/${{ steps.get_host.outputs.db-host }}/g' .env
            sed -i 's/3306/${{ job.services.mysql.ports['3306'] }}/g' .env
            mysql -uroot --password=test -h ${{ steps.get_host.outputs.db-host }} --port ${{ job.services.mysql.ports['3306'] -e "show databases;"
            php artisan app:prepare -vvv

Error


Database
information_schema
mysql
performance_schema
sys

  1   vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
      PDOException::("SQLSTATE[HY000] [2002] Connection refused")
$ telnet 172.26.0.1  32921 
Trying 172.26.0.1...
Connected to 172.26.0.1.
Escape character is '^]'.
J
8.0.23^]
telnet> Connection closed.

Runner Version and Platform

Version of your runner? 2.304.0 Ubuntu 22.04.2 LTS

christrt9 avatar May 23 '23 11:05 christrt9

Did you resolve this? I have a similar problem.

curtishall avatar Jul 23 '23 15:07 curtishall

@curtishall no i still have the issue.

christrt9 avatar Jul 24 '23 19:07 christrt9

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 15 days.

github-actions[bot] avatar Jul 29 '24 00:07 github-actions[bot]

This issue was closed because it has been stalled for 15 days with no activity.

github-actions[bot] avatar Aug 19 '24 00:08 github-actions[bot]

the issue stll exist

christrt9 avatar Aug 19 '24 18:08 christrt9