Unable to expose docker container port other than port 80 to host

1.5k views Asked by At

Im am running a Tendermint HTTP RPC server at port 26657 on docker container using ubuntu image.

docker run -itd --name t1 -p 26657:26657 tendermint

When I perform a curl operaion inside the container, i get the JSON reponse from the RPC server.

docker exec -it t1 curl localhost:26657/status

But when it try to use the curl operation on the host, then i get an error: "curl: (52) Empty reply from server"

curl localhost:26657/status

Initially I was running docker on a Windows machine. I thought there might be some issue with windows not able to talk with WSL Linux (which docker uses in Windows for ubuntu). So, I tried the same commands in a Linux Virtual Box running Ubuntu 20.04. Still the host ubuntu is not able to access the container server using curl/web browser.

I tried running a apache2 server at port 80 inside container and mapped to port 5000 (-p 5000:80). This worked and I was able to access the apache2 at localhost:5000 in the host. When I try to map 26657 to 5000 (-p 5000:26657) on the RPC server then the same issue happens. So the issue is only with ports other than port 80 in the container.

I tried "netstat -an" on the host machine and it says:"TCP 0.0.0.0:26657 0.0.0.0:0 LISTENING".

Tried running a simple Angular 11 HTTP lite server running at 4200 and mapped to host 4200. It was not able to map this port as well.

Also tried to telnet into port 26657 on host and was able to connect successfully using "telnet localhost 26657". When the container is terminated, then the telnet fails to connect which is ideal. But still not able to connect host using curl/web brower and get the JSON response from the container.

I just tried to run the tendermint RPC server on an Amazon EC2 instance. I was not able to access the port 26657 using the public IP. I guess there is something to do with the protocol on the 26657 port.

2

There are 2 answers

3
Ren On BEST ANSWER

I was running the Tendermint RPC server on "localhost" which cannot be accessed from outside. I should have started the server on 0.0.0.0

2
ariefs On

try to run this docker run -itd --name t1 -p 26657:26657 tendermint/tendermint

curl localhost:26657/status

{
  "jsonrpc": "2.0",
  "id": -1,
  "result": {
    "node_info": {
      "protocol_version": {
        "p2p": "8",
        "block": "11",
        "app": "1"
      },
      "id": "e0d34bb67c18d9025f6944de285f24e904de8c23",
      "listen_addr": "tcp://0.0.0.0:26656",
      "network": "dockerchain",
      "version": "",
      "channels": "40202111433038606100",
      "moniker": "dockernode",
      "other": {
        "tx_index": "on",
        "rpc_address": "tcp://0.0.0.0:26657"
      }
    },
    "sync_info": {
      "latest_block_hash": "5E59DCD523F574AA5B3961A9523B660716FDF9A3D90C72294285106E99614F18",
      "latest_app_hash": "0000000000000000",
      "latest_block_height": "170",
      "latest_block_time": "2021-05-16T12:08:26.1797685Z",
      "earliest_block_hash": "746D1580F6B7012D042230791CCED002AC327422D144BEE7BC2B203E1ECD6F39",
      "earliest_app_hash": "",
      "earliest_block_height": "1",
      "earliest_block_time": "2021-05-16T12:06:43.2085282Z",
      "catching_up": false
    },
    "validator_info": {
      "address": "ACC91433A4B84C4A53547A58418001CD55677F28",
      "pub_key": {
        "type": "tendermint/PubKeyEd12519",
        "value": "+hGKJ2w6dRevN0t2OEf/1uHoInggirrSHCDzyhwJuOo="
      },
      "voting_power": "10"
    }
  }
}

it works on my windows 10 machine with wsl2 + ubuntu 20.04..