1

I am building a Docker image from an Express-based app in a step of my GitHub action, then create a container from it and map the port 8080. But when I try to access the app through the container the connection gets refused.

Here is my GitHub Action definition:

name: CI

on:
  push:
    branches: [ "*" ]
    
jobs:

  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the branch
        uses: actions/checkout@v3
      
      - name: Build Docker Image
        run: |
          cd app && docker build -t my/testapp .
      
      - name: Start Testapp Container
        run: docker run -d -p 8080:8080 my/testapp
      
      - name: Check Docker Container
        id: check  
        run: docker ps
      
      - name: Test App in Container
        id: test
        run: curl -v http://localhost:8080/data

This is the output of step check. As you can see, the container is running properly:

CONTAINER ID    IMAGE       COMMAND                 CREATED                 STATUS                  PORTS                                       NAMES
7dcb27953e35    my/testapp  "docker-entrypoint.s…"  Less than a second ago  Up Less than a second   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   hungry_meninsky

But when I try to access the service inside the container via curl (step: test), I am getting the following error.

* TCP_NODELAY set
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* connect to 127.0.0.1 port 8080 failed: Connection refused
* Failed to connect to localhost port 8080: Connection refused
Sebastian Dine
  • 815
  • 8
  • 23
  • There are some tips on [this other question](https://stackoverflow.com/questions/65330029/access-a-container-by-hostname-in-github-actions-from-within-an-action) that might help you here as well. Another option could be to push the docker image first, and then use it as a job services configuration ([this blog is about this scenario](https://dev.to/duplys/cant-access-service-container-in-github-actions-heres-how-to-fix-it-10i1)) – GuiFalourd Sep 21 '22 at 15:00

0 Answers0