Github Action connection failure between multiple docker containers

Hi,

I have a Github Actions workflow like this, where it runs MySQL in the background. In Test App action, “my-app” tries to connect to mysql-test service via hostname “mysql-test” but fails even though both containers are running in the same “bridge” network. How can I access another container’s service (mysql-test, port 3306) using hostname or IP address, in this case from “my-app” container.

workflow "Publish workflow" {
  on = "push"
  resolves = ["Test App"]
}

action "Run MySQL" {
  uses = "actions/docker/cli@master"
  env = {
    MYSQL_DATABASE="test_db",
    MYSQL_ALLOW_EMPTY_PASSWORD="yes"
  }
  args = "run --network bridge -d --name mysql-test -p3306:3306 mysql:5.7"
}

action "Build App" {
  needs = ["Run MySQL"]
  uses = "actions/docker/cli@master"
  args = "build -f ./docker/php/Dockerfile -t my-app ."
}

action "Test App" {
  needs = ["Build App"]
  uses = "actions/docker/cli@master"
  args = "run --network bridge my-app /bin/sh -c \"php vendor/bin/phpunit\" "
}
2 Likes

To my knowledge, GitHub Actions isn’t designed to work in the manner that you’re describing. You can spin up a Docker container that can communicate with itself. You can spin up a Docker container that connects to an external service. But, as far as I know, there is no provision for one Action’s Docker container to communicate with another Action’s Docker container.

Also, when you specify “needs”, that means that the Action or Actions specified in “needs” must run to completion and return either neutral or success for the given Action to start. Because of this, in your sample file, “Build App” won’t start until “Run MySQL” finishes.

I hope that helps!

1 Like