skip to Main Content

I have a django project that is containerized in Docker. In a separate project, I am trying to use docker compose to load my django project as a service, and then use GitHub Actions to confirm that the django server is running.

Every attempt to run curl to test whether the django server is running has failed, with no response. I tried running the curl command INSIDE the container, using docker exec, and it fails with "connection refused".

If I docker compose build --no-cache, then docker compose up, and then curl -X GET localhost:8000/version/ locally, it works perfectly. It also works locally if I attempt to run curl from inside the container. It only fails in the github actions.

My docker-compose.yml file reads as follows:

services:
  blawx:
    build: https://github.com/Lexpedite/blawx.git#v1.3.40-alpha
    ports: 
      - "8000:8000"
    expose:
      - 8000
    volumes:
      - ./blawx/fixtures:/app/blawx/blawx/fixtures/nrcan-map

My github actions file looks like this:

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Build and run the Docker Images from docker-compose.yaml
      run: docker compose up -d
    - name: Show Running Containers
      run: docker ps
    - name: Check Blawx Heartbeat
      run: |
        docker exec -t nrcan-map-blawx-1 curl --retry 5 -X GET "localhost:8000/"
    - name: Shut Down Docker Containers
      run: docker compose down

The log shows the build action failing on Check Blawx Heartbeat, with error code 7, "connection refused."

When I tried running curl inside the host instead of the container, I got error code 52, "empty response."

If I am getting connection refused from inside the Docker container, that suggests to me that the problem is a Django security configuration issue. For Django, allowed hosts is set to ["*"] in the settings.

I suspect that there is some combination of using docker compose and django and github actions that isn’t playing nicely, but I haven’t been able to find it.

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    It turned out that the problem was being caused by the curl test being run too quickly - after the docker container was run, but before it was able to respond to requests.

    The solution was to add the following before the curl step.

      - name: Wait
        run: sleep 10s
    

  2. Might be related to IPv6 support of Docker, can you try passing -4 or --ipv4 option to curl?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search