skip to Main Content

I try to transfer my projects CI to GitHub Actions. For integration tests I need to start and access redis container. I am using info from this
article.
So code looks like this

build-artifacts:
    name: Build artifacts
    runs-on: ubuntu-latest
    services:
      redis:
        image: redis:3.2.12
        ports:
        - 6379:6379

I can access redis using localhost:6379 but I can’t access it using redis:6379. The article does not help. What I am doing wrong?

Thank you in advance.

2

Answers


  1. Chosen as BEST ANSWER

    So I figured out what was the problem. Docker network works only if you run your job inside container. And I had not.

    Here is example https://github.com/actions/example-services/blob/989ef69ed164330bee413f11ce9332d76f943af7/.github/workflows/mongodb-service.yml#L19

    And a quote:

    runs all of the steps inside the specified container rather than on the VM host. Because of this the network configuration changes from host based network to a container network.


  2. U need to host an external redis database because containers in GitHub Actions are isolated.
    For other hand u can prepare a docker container with all you need for testing and then u can run the tests inside.

    Un can take a look here https://github.com/gonsandia/github-action-deploy
    Its a custom action where u define the dockerfile and the scripts to runs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search