Connect to an Ubuntu container web-based interface from a Mac host

Hello all,

I have a running Ubuntu Docker container containing a tool that opens a web-based interface on a specific port like:

http://localhost:<dockerport>/<tool>

I want to connect to this url from my host, which is running MacOS, so the browser is Safari.

I start the container like:

docker run -p <hostport>:<dockerport> 

but am unable to connect and am stuck here. Anyone with a solution? Thanks in advance.

Ensure your application in the container is not only listening on localhost inside container. Can you connect from Linux host using curl?

Are you running that container in Docker Desktop, or in any other virtual machine running on macOS?

Please, also share why you think you were not able to connect. What error message was returned if any? It could be the output of curl as @bluepuma77 suggested,

First of all, thank you both for trying to assist me, much appreciated!

I run the Linux container in Docker Desktop on a Mac. The complete (pseudo) command:

docker run -p 9999:9999 -e DISPLAY=$LOCALIP:0 --rm --name <container> 
--privileged=true --mount type=bind,source=<hostpath>,taget=<containerpath> 
-it <container> bash

Starting the tool in a docker terminal as mentioned before, I get something like:

Remote Host: localhost
Local Port: 9999

Open an HTML browser on the remote host and paste this URL in it:

    http://localhost:9999/<tool>

Keep this process running and use <ctrl-c> to exit

In a second docker terminal I check the container with ‘docker ps’:

CONTAINER ID   IMAGE         COMMAND   CREATED          STATUS          PORTS                                         NAMES
9f234b937e1e   <container>  "bash"     15 minutes ago   Up 15 minutes   0.0.0.0:9999->9999/tcp, [::]:9999->9999/tcp   <container>

I am up to today unfamiliar with ‘curl’ (like I am only fairly new to Docker itself :upside_down_face:), but all following calls (I ran this from Mac host AND linux docker terminals) return the same error:

curl: (56) Recv failure: Connection reset by peer

calls tried:

curl http://localhost:9999
curl http://localhost:9999/<tool>
curl http://0.0.0.0:9999
curl http://0.0.0.0:9999/<tool>

I I need other specific curl calls, please let met know :victory_hand:

If your application really listens only on localhost, it won’t work. It has to listen on all container IP. If it listens only on localhost, it will be available only from localhost. Meaning: inside the container.

You added the “host-network” tag to the topic. I haven’t asked about it until you confirmed you used Docker Desktop. The host network would indeed be an alternative (mainly for testing), but you need to enable it in Docker Desktop and add “--net host” to the docker run command.

https://docs.docker.com/engine/network/drivers/host/#docker-desktop

Great, this did the trick. Thanks!