skip to Main Content

New to Docker and hit an issue I can’t seem to solve myself.

I have a node.js server that I dockerized. The app works perfectly when I run it on my local machine, but the second I send it to my home server, it receives no traffic.

I’ve double-checked that the hosting PC receives traffic on the correct port (5001) and accessed the container shell via docker exec -it <container_id> /bin/sh and run curl http://localhost:5001 to test connectivity.

My docker-compose.yml file appears to be correct:

services:
  app:
    build: .
    image: impurestclub/streamcontrol:1.0
    env_file:
      - path: .env
        required: true
    ports:
      - "5001:5001"  # Map port 5001 in the container to port 5001 on the host
    restart: unless-stopped

And, likewise, the settings within my node.js app should also be alright:

// Running the app
const port = process.env.PORT || 5001
app.listen(port, () => console.log(`Backend is running on port ${port}`))

Does anyone have any other troubleshooting steps I could try?

2

Answers


  1. Chosen as BEST ANSWER

    I figured it out, and the problem was unrelated to Docker.

    I had an issue with my OPNsense firewall where NAT reflection was configured in the port forwarding rules but not under advanced settings. This stopped me from accessing the server while using its external IP address.

    I changed the firewall configuration, and everything works perfectly now.


  2. You mentioned hosting PC gets traffic on port 5001, that part of network works correctly.
    Assuming curl request from inside docker works correctly on port 5001, the issue is in docker port mapping (traffic is not getting forwarded).
    As per docker port mapping document (https://docs.docker.com/engine/network/), a firewall rule is created for a port mapping. Please list firewall rules in docker host

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