Repository navigation
How to use act with a workflow that needs access to a local database? #6184
|
My CI workflow runs integration tests that need a PostgreSQL database. On GitHub Actions this works with the services:
postgres:
image: postgres:16
ports:
- 5432:5432When I run this locally with I tried What's the right way to handle service containers with act? Do I need to set up a Docker network manually? |
Replies: 1 comment
|
the service container hostname works on real github actions because they set up a docker network + DNS alias automatically. act doesn't do that by default. what works for me:
docker run -d --name pg -p 5432:5432 -e POSTGRES_PASSWORD=test postgres:16
act push --env DATABASE_URL=postgresql://postgres:test@host.docker.internal:5432/test
option 1 is more reliable. the built-in service container support in act has always been flaky with networking. |
the service container hostname works on real github actions because they set up a docker network + DNS alias automatically. act doesn't do that by default.
what works for me:
host.docker.internalresolves from inside the job container on docker desktop. on linux you might need--add-host=host.docker.internal:host-gateway.--network hostto act and change your test config to connect tolocalhost:5432instead of