Docker networking with nextcloud

Hi all!
Im a noob at docker still learning and so far I managed to find all the info I needed by googling solutions…
However im really stuck at one part so please shed some light…

As far as I understand docker creates a bridge as default ie containers should be able to access the internet and should be able to get connected to by exposing ports?

Im using an image called nextcloud that I install
And I run it by using -p 8080:80 so it exposes ports I need to connect to it.
Firewall has been allowed and router ports forwarded.
Im using file sharing services on port 445 and I am able to connect to my server without problems so im sure the conection works.
Im also using tplink’s DDNS thats easy to setup on the router (example
It all works I even RDP into my server from 4G.

Now here is the problem, on LAN I am able to connect to nextcloud however from outside the network I am unable to and I belive the container has no conectivity as trough the log I see an error for hostname and says using 172.0.x.x… Im not sure it should be using that since my subnet is on

What am I doing wrong with exposing ports?
I have seen a command -h that maybe I would need to use to set hostname by that?

Any help is appreciated!

Okay, I started my message 3 times, because every time I wanted to suggest something, I relaized you included the answer in your original question… So let’s hope this time I will not miss anything.

Have you tried other ports too with Docker and other images? For example nginx? Just to make sure that is not the problem. Your connection should work, but you can try to define the exact IP address when you forward the port:

docker run -p 192.168.1.X:8080:80 ..

This is because Docker has its own network with its own IP range. Since you have Docker Desktop and everything runs in a virtual machine, you will not see that network. You don’t need to set the hostname of the container.

1 Like

WSL2 only binds ports to localhost of the windows host. It needs a portforwarding from hostip:8080 to localhost:8080 in order to make the container accesible from the outside.

Something like should do the trick.

netsh interface portproxy add v4tov4 listenport=8080 listenaddress=192.168.1.x connectaddress= connectport=8080

@sale666 make sure to replace the x in the example command with your real host’s ip!

1 Like

It is true, but the category name indicates that we are talking about Docker Desktop and that should work even with the WSL backend. I tried, because I wasn’t sure either.

1 Like

Thanks for cleariying.

Seems the portforwarding thing is only required if docker-ce is run in WSL2 (without Docker Desktop).

1 Like

Thanks for your replies…
So this is what im doing right now im using my DDNS on android going to file manager and I use my tplink DDNS and boom it takes me to my shared files on my E: drive I setup as a share and that’s over 4G no problem.
So the server is visible and works.

Now I open nextcloud app add the same DDNS address and nothing I cannot connect…
I attempted this runs:
a) docker run -p 8080:80 nextcloud
b) docker run -p -h localhost nextcloud
c) docker run -p nextcloud

B and C give me port in use error…
I have forwarded port 8080 to (server) to 8080 internal port
I have reviewed the firewall all ports that I need are ALLOWED as TCP and UDP.
I have now attempted to put my server in DMZ on my Archer AX50 TPLINK router and it did not help.

Been attempting 3 days to install and configure nextcloud really frustrating

Have you deleted the previous nextcloud container before trying to run the new containers? If you have, and something is really listening on port 8080, you should find out what. I don’t know if it can happen on Windows but it was surprising t me on mac, that I forgot to stop service running on the host and the desktop allowed me to listen on the same port that the already running service used. When I wanted to access the port, I got an output but not from my container.

Since you did not mention first two suggestions, could you try it?