0

I have my server running under docker and start it with the command serve(app, listen='*:5000').

I can:

  • access it in container under both 127.0.0.1:5000 amd localhost:5000
  • access it from outside the container under localhost:5000

I cannot:

  • access it from outside container under '127.0.0.1:5000'
  • access it from local network using local ip (and this is what matters the most to me)

I was trying to pass the local address into the serve command but it throws error saying that the address cannot be accessed. Also tried the host='0.0.0.0'. Did not help.

Would anyone know how to make it visible outside of my machine?

Chris
  • 570
  • 2
  • 9
  • 19
  • How are you launching the container? It's also very odd, from outside the container, that `127.0.0.1` would not work but `localhost` would, since these are usually synonymous. – David Maze Oct 31 '20 at 11:19

2 Answers2

0

ok so i found a solutions that seems to do the trick. the problem was wsl. at github wsl repo there is a script that sets a bridge. below i post the code so it does not perish. credit to edwindijas

$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

if( $found ){
  $remoteport = $matches[0];
} else{
  echo "The Script Exited, the ip address of WSL 2 cannot be found";
  exit;
}

#[Ports]

#All the ports you want to forward separated by coma
$ports=@(80,443,10000,3000,5000);


#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";


#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";

#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";

for( $i = 0; $i -lt $ports.length; $i++ ){
  $port = $ports[$i];
  iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
  iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}
Chris
  • 570
  • 2
  • 9
  • 19
-1

If you have not already done so, try exposing port 5000.

This can be done by adding

EXPOSE 5000

to your Dockerfile. You will also need to have host='0.0.0.0' in your serve in order to be able to access your page from the local network.

  • thanks but i did expose the port 5000 in the docker file. that is why i can access the server from outside. but what is peculiar it only works on `localhost:5000` not `127.0.0.1:5000` – Chris Oct 31 '20 at 06:07
  • Are you running Docker for Windows, Mac, or Linux? In the past I have had to open up the firewall for a port in order to be able to access it from a different server on the local network. – raisin.brannum Oct 31 '20 at 06:20
  • its a linux version of docker installed under wsl2 – Chris Oct 31 '20 at 06:28
  • You may want to try opening up port 5000 in your firewall, similar to what was done here: https://www.nextofwindows.com/allow-server-running-inside-wsl-to-be-accessible-outside-windows-10-host – raisin.brannum Oct 31 '20 at 06:49
  • did that. still no success :( – Chris Oct 31 '20 at 07:43
  • 1
    `EXPOSE` in a Dockerfile does almost nothing; it's useful documentation but won't solve this problem. – David Maze Oct 31 '20 at 11:20
  • @DavidMaze, my bad, you are correct that expose in the Dockerfile does nothing without using the -P flag in docker run. – raisin.brannum Oct 31 '20 at 14:28