-
I’m trying to build a project which has a docker-compose.yml file, so I’m trying to test both the docker-compose and the project at the same time. The docker-compose.yml file has a web container service for a django application and an nginx service for static files. docker-compose.yml
Dockerfile:
Database is external to the application, so I try to use a postgres service for it in the actions workflow: pythonapp.yml:
In my ci.env and my project I try to use POSTGRES_HOSTNAME as ‘postgres’ When the action initialializes it creates the postgres service container as so:
So it looks like ‘postgres’ is the right name (–network-alias postgres), however when my django application tries to run tests I get the following:
"could not translate host name “postgres” to address: Name or service not known" It’s like they’re on two separate networks, the service containers and the docker-compose containers I boot up, how do I get them on the same network so they can contact each other? Here’s the result of ‘docker ps -a’:
Here’s the result of ‘docker network ls’:
I know there’s a “container:” thing in Github actions, but isn’t that just for Dockerfile containers or docker hub containers? Can I specify a docker-compose container to run alongside postgres:11? It does work if I just overload the docker-compose.yml with a file that has an extra postgres service, but I don’t really want to do that I want to test the docker-compose.yml file as is and write tests against the product as it ships or as close to it as I can get. This whole thing is hard to google, if I look at “github actions container” I’ll get a bunch of irrelevant things. I can’t seem to define a network for the postgres service as in " networks: default: external: leyfisbref_default" or something like that, the yml would stop parsing at “networks:”. I might be able to use ${{ job.services.postgres.network }} but I don’t think docker-compose has a command line flag for overriding the network. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Naturally, as soon as I had buckled and asked for help I figured it out on my own. I can connect the network like so: docker network connect ${{ job.services.postgres.network }} leyfisbref_web It will still fail in the entry point but the test command will run ok. If anyone has a better idea I’d be very grateful Here’s my new pythonapp.yml:
|
Beta Was this translation helpful? Give feedback.
Naturally, as soon as I had buckled and asked for help I figured it out on my own.
I can connect the network like so:
docker network connect ${{ job.services.postgres.network }} leyfisbref_web
It will still fail in the entry point but the test command will run ok. If anyone has a better idea I’d be very grateful
Here’s my new pythonapp.yml: