I’m having issues with a Docker setup in GitHub Actions. It works fine on local machines but fails in the pipeline. The problem is with an n8n container that should expose an HTTP API on port 5678.
Here’s a simplified version of my docker-compose setup for n8n:
n8n:
image: docker.n8n.io/n8nio/n8n
ports:
- "5678:5678"
environment:
- N8N_HOST=n8n:5678
- N8N_PORT=5678
- N8N_PROTOCOL=http
- DB_TYPE=postgresdb
When I try to access it using curl, I get a connection refused error:
curl --fail http://localhost:5678/api/v1/docs/ || exit 1
This works fine locally but fails in GitHub Actions. I’ve tried different ports too. Any ideas why this might be happening in the CI environment but not locally? Could there be some network or container isolation issue specific to GitHub runners?
I’ve encountered similar issues with Docker in CI environments. In GitHub Actions, the networking setup can be a bit different from local machines. One thing to check is if the container is actually running and the port is exposed correctly.
Try running ‘docker ps’ to verify the container status and port mapping. Also, you might want to add a short delay after starting the container before attempting to access it. Sometimes services need a moment to fully initialize.
Another potential solution is to use ‘host.docker.internal’ instead of ‘localhost’ in your curl command. This often works better in CI environments:
curl --fail http://host.docker.internal:5678/api/v1/docs/ || exit 1
If that doesn’t work, you could try exposing the port differently in your docker-compose file, like this:
ports:
This explicitly binds to all interfaces, which might help in the GitHub Actions environment.
hey markseeker, had similar probs. try checkin logs with ‘docker logs n8n’ to see if theres any startup errors. also, make sure ur using the right network in GH actions. sometimes u gotta use the ‘docker’ network instead of ‘host’.
try this:
docker network create mynetwork
docker run --network mynetwork -p 5678:5678 n8n
then curl using the container name:
curl --fail http://n8n:5678/api/v1/docs/ || exit 1
hope this helps!
I’ve dealt with similar Docker issues in CI environments before. One thing that’s often overlooked is the container’s health check. GitHub Actions might be trying to access the service before it’s fully ready.
Try adding a health check to your n8n service in the docker-compose file:
n8n:
image: docker.n8n.io/n8nio/n8n
ports:
- ‘5678:5678’
environment:
- N8N_HOST=0.0.0.0
- N8N_PORT=5678
healthcheck:
test: [‘CMD’, ‘curl’, ‘-f’, ‘http://localhost:5678/healthz’]
interval: 10s
timeout: 5s
retries: 5
Then in your GitHub Actions workflow, wait for the health check to pass before attempting to access the service:
docker-compose up -d
docker-compose run n8n /wait-for-it.sh n8n:5678 -t 60
This approach has solved similar issues for me in the past. It ensures the service is truly ready before you try to interact with it.