Access both another container AND a server running on WSL 2 from within a container

Hi !
I’m using Docker Desktop for Windows with WSL 2 integration to run a TUSD and minio containers and I’m running a web server using WSL 2.

My TUSD container requires 2 endpoints:

  • One is a route from my web server on the host
  • One is the minio container endpoint

Here’s my docker compose file for the TUSD service

tusd:
        image: tusproject/tusd
        # Some entrypoint values have been omitted for readability
        entrypoint:
            - "tusd"
            # My web server route on the host
            - "-hooks-http=http://${HOST}:${PORT}/tusd-hooks"
            # my minio container endpoint
            - "-s3-endpoint=http://minio:9000"
        ...

Until a few days ago everything was working fine. I could send a file to the TUSD server which would call my web server on the host and then store this file in the minio container.
But now I can reach my TUSD server but TUSD cannot reach my web server anymore.

As you can see in my docker file I need to provide HOST for my web server endpoint which is my WSL 2 ip address. Since it is not static I had to update this value from time to time but this time even updating the HOST value did not work.

Being quite new to docker I’m not even sure if this is a wrong network config for my TUSD container or maybe just a docker desktop and/or a WSL 2 update that caused this problem.

Any help would be greatly appreciated.

Cheers.

I don’t know why it worked before and not now, but if I understand you correctly, tusd can’t access the webserver which should be accdessible on ${HOST}:${PORT}.

Since it is Docker Desktop, have you tried using host.docker.internal instead of the IP address of the WSL distribution? When you run a service in a WSL distribution that will be available on localhost from the Windows host. host.docker.internal is an alias exactly for that. It will access a service on the Windows host’s localhost.

Hi @rimelek !

I tried using host.docker.internal but I’m not sure how to use it.
Right now this is my entry in my docker-compose file: -hooks-http=http://host.docker.internal:${PORT}/tusd-hooks.
Unfortunately this is what I get when I’m calling the tusd server

Post “http://host.docker.internal:8080/tusd-hooks”: dial tcp 192.168.65.254:8080: connect: connection refused

I tried the command ping host.docker.internal directly in the TUSD container and I can reach the host.
I also confirm that I can call my web server from Windows.

If I understand what you’re saying it makes sense that using host.docker.internal should work because my container can ping this address and windows can access my web server on localhost and yet it doesn’t seem to work.

Can you access the port from Windows using localhost:8080?

Yes I can access all my web server endpoints from windows

If you could open the website from windows using localhost:8080 in the webbrowser then host.docker.internal should work. If not, then I have no idea. You can try with another service. I tested with a simple python service like this in a wsl2 distribution:

python3 -m http.server 8888

If you can access that, then there is something with the other port.

Yes I forgot t mention I have other services for instance the Minio container and I can access its interface in my browser in windows at http://localhost:9090.
Maybe the problem comes from the windows firewall? That’s I can think of.

Anyway thanks a lot for your help.

Cheers

It now works as it used to. I didn’t change anything except keep up with the latest docker desktop version.