How to expose REST API running inside a docker container?

Hi

I am running go-algorand in an Ubuntu 20.04 docker container with this Dockerfile: https://github.com/jwgibanez/docker-go-algorand/blob/master/Dockerfile

Inside the container I am able to access the REST API (port 8080) however unable to on the host machine (a mac).

I was running this docker command:
docker run -it -p 8080:8080 {go-algorand image id}

When I try to access the REST API on the host (0.0.0.0:8080), I get this error:
curl: (52) Empty reply from server

Has anyone encountered this before? Hope someone could help me.

Thanks,
Jan

1 Like

Can you share the curl command you used?

1 Like

Hi Tim,

Inside the container, this call returns successfully:
curl localhost:8080/swagger.json

But on the host it fails:

docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 578020ab694e f5b963d67552 "/bin/bash" 34 seconds ago Up 33 seconds 0.0.0.0:8080->8080/tcp sweet_fermat curl localhost:8080/swagger.json
curl: (52) Empty reply from server
$ curl 0.0.0.0:8080/swagger.json
curl: (52) Empty reply from server

1 Like

Using the sandbox app Algorand publishes (which is really just managing docker for you), I’m able to communicate over the exposed ports.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fd473a225486 algorand-sandbox:stable "/opt/algorand/start…" 4 minutes ago Up 4 minutes 0.0.0.0:4001-4002->4001-4002/tcp sandbox

and use curl http://0.0.0.0:4001/swagger.json to get the swagger.json.

The sandbox is covered here - https://github.com/algorand/sandbox

1 Like

You need to change the config.json file in the data directory, change this setting:
“EndpointAddress”: “127.0.0.1:0”,
to:
“EndpointAddress”: “127.0.0.1:8080”,

Otherwise it listens on a different port each time.

1 Like

Hi Tim, aojjazz,

I was able to make it work by:

  1. Sticking to non-sandbox repo https://github.com/algorand/go-algorand
  2. Modifying /data/config.json to
    {
    “EndpointAddress”: “:4001”
    }
    similar to https://github.com/algorand/sandbox/blob/master/config/config.json
  3. Publish port 4001 when running container

I am now able to access the REST API outside the container via port 4001.

Thank you both for your guidance.

Jan

2 Likes

Maybe you already had other service using 8080 port?