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