mathworks / matlab-proxy

Python® package enables you to open a MATLAB® desktop in a web browser tab.
Other
47 stars 23 forks source link

How can I access a docker browser-based matlab in a remote linux server directly from my windows local browser? #11

Closed cuixing158 closed 1 year ago

cuixing158 commented 1 year ago

Following matlab mirror tutorial on dockerhub, I managed to run a docker browser matlab on a remote Linux service. Here the host is the remote ubuntu server, which can be accessed via the browser address http://localhost:8888/index.html. In the same way, I built the container with the following command.

docker run -it --rm -p 8888:8888 --shm-size=512M mathworks/matlab:r2022b -browser

However, the problem is that the application can only be accessed from the browser on the host computer, not from my local computer or from a different computer's browser on the same LAN.

During this time, I also tried through the instructions for using the advanced commands in this repository, and the start container command was as follows:

docker run -it --rm -p 8888:8888 -e MWI_APP_PORT=8888  --shm-size=512M mathworks/matlab:r2022b -browser

I have had a hard time finding a solution by searching the web and trying to access it by specifying the following URL address, but nothing works.

"http://localhost:8888/index.html"
"http://<linux_ip_id>:8888/index.html"
"http://<windows_ip_id>:8888/index.html"
"http://<container_ip_id>:8888/index.html"

Also, I understand from other sources that I need to set the network method between the host and my local computer to be bridged and its solution is a VM VirtualBox Manager setup. But my case is different, the host is a remote standalone ubuntu server. the docker container communicates with the host by default as a bridge, but I tried to run the docker container by building it with the network connection specified as --network=host and the above access address still doesn't work!

Note: My local computer is a windows 10 system, which is on the same LAN as the remote Linux system, i.e. I can ping the server IP address normally, and I can also connect to it via ssh.

cuixing158 commented 1 year ago

In my subsequent attempts, I have occasionally been able to access matlab via the first http://localhost:8888/index.html link from google-chrome on my local windows system on a few occasions, but it is often unstable and gives a "http error 408 request timeout" error. No other URL links work, I don't know why. matlab_error

I turned off the firewall on linux server,but it does't work!

prabhakk-mw commented 1 year ago

@cuixing158

In short, it looks like you are hitting some network related issues. The screenshot you've provided leads me to believe that you've successfully connected to matlab-proxy's webserver on your linux box, but once loaded is unable to communicate with the webserver.

Please check the terminal from which you've launched the docker container to see if there are any error messages which may indicate if matlab-proxy was able to launch MATLAB and serve it successfully.

Given the information you've provided so far it seems like you are able successfully use MATLAB from the linux machine directly, and are only having issues when you attempt to access it from another machine.

Listed below is some background and things you could try out.

If the linux machine on which your docker container is running is truly accessible via your network, then you should be able to access the webserver running on the the remote linux machine using the FQDN of the machine as shown below:

http://<FQDN of your linux machine>:8888/index.html

This should allow you to connect to the remote linux machine from your Windows machine as long as its on the same network.

If you want to access the webserver running on your remote linux machine from Windows while using the localhost syntax then you would need to enable to use SSH port forwarding to tunnel into that machine. For example:

# Execute on your windows terminal
ssh -L 8888:<FQDN of linux machine>:8888 <yourUserName>@<FQDN of linux machine>

This will then allow you to access the webserver on your Windows machine using

http://localhost:8888/index.html

Now, including the docker aspect into the picture. The docker run commands you have listed should be sufficient to map the ports from within your container to the host machine on which the container is running. ie: -p 8888:8888 . You shouldn't have to use the network=host command if you do this.

As a debugging tool, you could attempt to run the NGINX webserver on your linux machine through docker and test to see whether you are able to access that from the windows machine.

The steps to do so would be:

  1. On your linux machine, start the NGINX container as follows:
     docker run -it --rm -p 80:80 nginx:latest
  2. This command should start a webserver on port 80 of your linux machine which can be accessed from <FQDN of linux machine>:80

If successful you should see a page similar to the one shown below: chrome-capture-2023-1-8

  1. Attempt to access this webserver from your windows machine with the information listed above.

Hopefully this information would've provided enough context to help resolve the issue.

Please feel free to re-open this issue, if you are in need of more assistance!

Thank you for using MATLAB and matlab-proxy!

cuixing158 commented 1 year ago

Hi,@prabhakk-mw

Thank you very much for your very detailed answer, unfortunately using your suggested http://<FQDN of your linux machine>:8888/index.html is still inaccessible in my browser on my local windows computer. On the linux server everything is fine, both and the localhost method.

The same goes for the NGINX container, which is accessible by the browser on linux, but not on windows.

I can't access it at all on my local window now anyway, which was occasionally successful before. The docker running on linux starts and stops the container without any error messages, which means that everything is working fine on it.


Again, I'll go over my environment configuration in detail.

FQDN query on linux:

hostname -f # or hostname 

output:

longhorn-PowerEdge-R940xa

IP address on linux:

ip address

output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno145: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 34:73:5a:9d:8a:94 brd ff:ff:ff:ff:ff:ff
    altname enp23s0f0
    inet 192.168.45.170/24 brd 192.168.45.255 scope global noprefixroute eno145
       valid_lft forever preferred_lft forever
    inet6 fe80::1af3:71a0:c7a0:5bb5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: eno146: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 34:73:5a:9d:8a:95 brd ff:ff:ff:ff:ff:ff
    altname enp23s0f1 ... # omit
  # omit

so ip address is: 192.168.45.170

IP address on cmd windows:

ipconfig

output

Ethernet adapter Ethernet :

   Connection specific DNS suffix . . . . . . . : *** # omit
   Local Link IPv6 Address. . . . . . . . : *** # omit
   IPv4 address . . . . . . . . . . . . : 192.168.202.153
   Subnet Mask . . . . . . . . . . . . : 255.255.255.0
   Default gateway . . . . . . . . . . . . . : 192.168.202.254

Ethernet adapter vEthernet (Default Switch):

   Connects to a specific DNS suffix . . . . . . . :
   Local Link IPv6 Address . . . . . . . . : *** # omit
   IPv4 address . . . . . . . . . . . . : 172.17.242.193
   Subnet Mask . . . . . . . . . . . . : 255.255.255.240
   Default gateway . . . . . . . . . . . . . :

Ethernet adapter vEthernet (nat):

   Connection specific DNS suffix . . . . . . . :
   Local Link IPv6 Address . . . . . . . . : *** # omit
   IPv4 address . . . . . . . . . . . . : 172.17.224.1
   Subnet Mask . . . . . . . . . . . . : 255.255.240.0
   Default gateway . . . . . . . . . . . . . : #omit
#omit

so ip address is: 192.168.202.153.

Looking at the IP addresses, they don't belong to the same network segment, suspect this is the reason? But on windows I can connect via ping 192.168.45.170 and ssh <my-name>@192.168.45.170 can log in successfully.


Earlier and now I started docker locally in vscode on windows as a remote linux server. vscode uses the following plugins. Microsoft's "Remote - SSH" "docker"

prabhakk-mw commented 1 year ago

Did you attempt to use SSH port forwarding ssh -L 8888:192.168.45.170:8888 <my-name>@192.168.45.170?

Execute this on a terminal and leave the session open. Then navigate to your browser and attempt to access the proxy url.

cuixing158 commented 1 year ago

@prabhakk-mw Thank you very much, after executing ssh -L 8888:192.168.45.170:8888 <my-name>@192.168.45.170 on a windows terminal, I can open MATLAB in my local browser.

The following URLs can be accessed by local windows browsers:

http://localhost:8888/index.html
http://<container_ip_id>:8888/index.html

After looking and learning, the ssh -L syntax rules:

ssh -L [listen to interface:]listen_to_port:target_host:target_port username@hostname

where listen to interface is the default 0.0.0.0 i.e. localhost

Although the problem is solved, I am very curious why I can't access it via http://<FQDN of your linux machine>:8888/index.html or http://<linux_ip_id>:8888/index.html? Or what can I do to access with this address? I don't know much about linux networking, thanks again