1

Hey i need help with port forwarding on docker. Look here that i have created a container and exposed ports

codespace:/workspaces/ProxyNode> docker ps
CONTAINER ID   IMAGE             COMMAND        CREATED         STATUS         PORTS                                                                                                                                   NAMES
524fa7457520   proxy-node   "yarn start"   7 minutes ago   Up 7 minutes   0.0.0.0:32770->1080/tcp, :::32770->1080/tcp, 0.0.0.0:32769->3000/tcp, :::32769->3000/tcp, 0.0.0.0:32768->4050/tcp, :::32768->4050/tcp   relaxed_benz

Executing curl inside container

codespace:/workspaces/ProxyNode> docker exec -it 524fa7457520 sh
# curl localhost:3000/stats
{"message":"Node stats","stats":{"bytesSent":0,"bytesReceived":0,"throughputSent":0,"throughputReceived":0,"duration":0,"tokensSpent":0,"spentTokens":{"wei":"0","ether":"0","human":"0"}}}

Executing outside the container(host)

codespace:/workspaces/ProxyNode> curl localhost:32769/stats
curl: (56) Recv failure: Connection reset by peer

What is the problem here? I think i have exposed the ports correctly

Sudhan
  • 306
  • 4
  • 13
  • what shows `iptables -L`? – pierpy Apr 07 '23 at 08:51
  • 2
    The issue is most likely that whatever you're running in the container is bound to localhost (or 127.0.0.1). It needs to be bound to 0.0.0.0 to accept connections from outside the container. If you need further help, you need to show the code that listens for connections. – Hans Kilian Apr 07 '23 at 08:57
  • @pierpy Fatal: can't open lock file /run/xtables.lock: Permission denied – Sudhan Apr 07 '23 at 08:57
  • @HansKilian I am actually running a express application in port 3000 inside the container. I listened the server using `server.listen(3000)`. How i am supposed to bound it to 0.0.0.0? – Sudhan Apr 07 '23 at 08:58
  • 1
    @Sudhan Change it to `server.listen(3000, '0.0.0.0')` – Hans Kilian Apr 07 '23 at 09:00
  • @Sudhan just for checking... Maybe you can run `sudo iptables -L` ? – pierpy Apr 07 '23 at 09:02
  • @pierpy https://hastebin.skyra.pw/fexovigalu.pgsql – Sudhan Apr 07 '23 at 09:09

0 Answers0