Search code examples
linuxmacosnetwork-programmingssh

is it feasible to run a dockerized locatunnel on Mac?


As an alternative to the very famous ngrok I used to use efrecon/localtunnel docker image to expose my http server on the internet for testing purposes.

With linux I used to:

  • start my local HTTP server (let's say on port 8080)
  • start a container running the efrecon/localtunnel image with --network host:
    docker run -it -d --name localtunnel --network host efrecon/localtunnel --port 8080
    
  • fetch the provided URL:
    export LOCAL_TUNNEL_URL=$(docker logs localtunnel | cut -d ' ' -f 4)
    
  • et voilà:
    curl $LOCAL_TUNNEL_URL/hello
    

Of course, with MacOs it's not possible to use the --network=host flag but I'm not finding the correct way to perform the same. I tried multiple combinations like:

docker run -it -d --name localtunnel -p 8443:8080 efrecon/localtunnel --port 8080
curl $LOCAL_TUNNEL_URL:8443/hello

docker run -it -d --name localtunnel -p 443:8080 efrecon/localtunnel --port 8080
curl $LOCAL_TUNNEL_URL/hello

docker run -it -d --name localtunnel -p 80:8080 efrecon/localtunnel --port 8080
curl $LOCAL_TUNNEL_URL/hello

docker run -it -d --name localtunnel -p 9090:8080 efrecon/localtunnel --port 8080
curl $LOCAL_TUNNEL_URL:9090/hello

but none of them gave me results, only a dangling request waiting indefinitely to be achieved. Any direct experience on how is localtunnel remote port-forwarding configured?


Solution

  • Interesting question, I think is something not specified in the documentation that's why you incurred in this.

    I don't think it's feasible, because the dockerized version of Localtunnel, implementing the reverse port-forwarding, needs the process to which the call is redirected to be on the same host, so on localhost:8080. The problems are two: you cannot pass the -p 8080:8080 because port 8080 is already occupied on you local machine by your local server process and, besides that, even if it would have been possible, the remote host is forwarding the calls to the container on port 8080, your process should be reachable on the localhost:8080 of the container, but it's not, because the server process is outside the container. The advantage of Linux is that Docker can share the host network, which doesn't only mean that every container is reachable via localhost, but also the opposite thing, which means that every container can reach any other container or local process on localhost too.