Cannot communicate with MySQL Service

Hi,

I cannot get anything to connect to my service, which is mysql. I cannot fathom what I’m missing.

I am running a mysql service, and connecting to it from another docker container like so:

name: "Build and Test"

on:
  push:
    branches:
    - '**'

jobs:
  build-container:
    name: Build Container
    runs-on: ubuntu-latest
    steps:

    - name: Checkout
      uses: actions/checkout@master

    # Build the Docker image and push to Google Container Registry
    - name: Build Container
      run: |
        docker build -t test .
        docker save test > test.tar

    - name: Archive production artifacts
      uses: actions/upload-artifact@v2
      with:
        name: test
        path: test.tar
        retention-days: 1

  run-tests:
    runs-on: ubuntu-latest
    needs: [build-container]
    services:
      database:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: password
        ports:
          - 3306:3306
        volumes:
          - ${{ github.workspace }}/tests/mysql-bootstrap.sql:/docker-entrypoint-initdb.d/01-setup.sql

    steps:
    - name: Download the radius test container
      uses: actions/download-artifact@v2
      with:
        name: test

    - name: Load docker container
      run: |
        docker load --input test.tar

    - name: Run Tests
      run: |
        docker run --network ${{ job.services.database.network }} \
        -e DATABASE_DB='main' \
        -e DATABASE_HOST='database' \
        -e DATABASE_USER='main' \
        -e DATABASE_PASSWORD='pass' \
        -e DATABASE_PORT=${{ job.services.database.ports['3306'] }} 
        test perl t/unit_networking.t

I’ve also tried running a docker ps -a during the run commands and cannot see the mysql service.

I’ve also tried running a simple connect command like so:

docker run --network ${{ job.services.database.network }} mysql:5.7 mysql -h database -uroot -ppass --port ${{ job.services.database.ports['3306'] }} -e "USE main; SHOW tables;"

I have also tried using hosts 0.0.0.0 and 127.0.0.1. This also doesn’t work, they all result in:

ERROR 2003 (HY000): Can't connect to MySQL server on 'database' (111)

Am I missing a fundamental problem here?

@outrunthewolf,

You can try to use “jobs.<job_id>.services.<service_id>.options” to set some health check options to make sure the service is running.

I added this:

options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

Genuinely thought it was a race condition but it always seems to be unhealthy… So at least I know now that the mysql container isn’t working for some reason.

Looks like its mysql version 5.7… im investigating now

@outrunthewolf,

Looks like its mysql version 5.7… im investigating now

Maybe you can try other version of MySQL image, such as the latest 8.xx.