Reputation: 2292
In my github actions workflow I am getting this error (ECONNREFUSED) while running my jest test script. The test uses axios to connect to my api which is running in a container bootstrapped via docker-compose (created during the github workflow itself). That network has just has 2 containers: the api, and postgres. So my test script is, I am assume, on the "host network" (github workflow), but it couldn't reach the docker network via the containers' mapped ports.
I've narrowed down the issue as follows. When I modified the compose file to rely on the default network (i no longer have a networks:
in my compose file):
So it looks as though the containers were never attached to the default bridge network.
It looks like I just have the wrong paradigm. After reading this: https://help.github.com/en/actions/configuring-and-managing-workflows/about-service-containers
I realise this is not how GA expects us to instantiate containers at all. Looks like I should be using services:
nodes inside the workflow file, not using containers from my own docker-compose files. 🤔 Gonna try that...
Upvotes: 3
Views: 4256
Reputation: 2292
So the answer is:
services:
in your workflow .yml file to launch your containers, which must be public docker images. If your container is based on a private image or custom dockerfile, it's not supported yet by GA.So instead of "docker-compose up" to bootstrap postgres + my api for integration testing, I had to:
so npm run start & npm run <test launch cmds>
. This worked.
Upvotes: 4
Reputation: 3194
There are several possibilities here.
Since you are using docker compose, when you start the api container, publish the endpoint that the api is listening on to the host machine. You can achieve this by doing:
version: 3
services:
api:
...
ports:
- "3010:3010"
in your docker-compose.yml
. This will publish the ports, similar to doing docker run ... ---publish localhost:3010:3010
. See reference here: https://docs.docker.com/compose/compose-file/#ports
By default, docker-compose will create a network called backend-net_default
. Containers created by this docker-compose.yml
will have access to other containers via this network. The host name to access other containers on the network is simply the name of the service. For example, your tests could access the api endpoint using the host api
(assuming that is the name of your api service), e.g.:
http://api:3010
The one caveat here is that the tests must be launched in a container that is managed by that same docker-compose.yml
, so that it may access the common backend-net_default
network.
Upvotes: -1