I have a service container (postgres) running. As outlined in workflows/postgres-service.yml
The job and all the steps are running on a Linux Runner (not inside a docker container). But, I’d like to invoke a docker container on the runner to run a command inside a container talking to the service container.
steps: - name: test postgres connection run: psql -h localhost -d postgres -p 5432 -U user -t -c 'SELECT datname FROM pg_database;'
This works. But now I’d like to run the exact same command from within a docker container targeting the service postgres container:
steps: - name: test docker connection run: docker run --rm postgres:11.8-alpine sh -c "exec psql -h postgres -d postgres -p 5432 -U user -t -c 'SELECT datname FROM pg_database;" # fails # Error: raw error: psql: could not translate host name "postgres" to address: Name does not resolve
This fails, because the 2 containers are on different networks.
Is it possible to run the jobs on Linux Runner (not container) while invoking a docker container with
docker run and having said container talk to the service container?