Jin Lover
Jin Lover

Reputation: 9

Why does VSCode port forwarding work without explicit Docker port forwarding, while SSH tunneling fails?

I’m trying to access Jupyter Lab running inside a Docker container in host server, from my local machine via SSH tunneling. The connection works fine between the local and host and the host and container, but when I try to access the Jupyter Lab URL from my local machine, I get the error.

What I’ve Tried:

ssh -ttL 8888:127.0.0.1:8080 USER@SERVER_IP -p SERVER_PORT \
    "ssh -ttL 8080:172.17.0.2:8888 USER@SERVER_IP -p SERVER_PORT \
    'docker exec -it DOCKER_NAME /bin/bash -c \"tmux attach -t 0\"'"

For this command, I can connect to docker container, and I execute jupyter lab inside docker container, with:

jupyter lab --allow-root --port 8888 -i 0.0.0.0 --no-browser --port-retries=0```

and what I've seen trying to connect localhost:8888 in my local machine:

debug1: channel 3: new [direct-tcpip]
debug1: Connection to port 8080 forwarding to 172.17.0.2 port 8888 requested.
debug1: channel 4: new [direct-tcpip]
channel 3: open failed: connect failed: Connection refused
channel 4: open failed: connect failed: Connection refused
debug1: channel 3: free: direct-tcpip: listening port 8080 for 172.17.0.2 port 8888, connect from 127.0.0.1 port 38198 to 127.0.0.1 port 8080, channels 5
debug1: channel 4: free: direct-tcpip: listening port 8080 for 172.17.0.2 port 8888, connect from 127.0.0.1 port 38202 to 127.0.0.1 port 8080, channels 4
debug1: Connection to port 8080 forwarding to 172.17.0.2 port 8888 requested.
debug1: channel 3: new [direct-tcpip]
channel 3: open failed: connect failed: Connection refused
debug1: channel 3: free: direct-tcpip: listening port 8080 for 172.17.0.2 port 8888, connect from 127.0.0.1 port 38206 to 127.0.0.1 port 8080, nchannels 4
debug: Connection to port 8080 forwarding to 172.17.0.2 port 8888
debug1: channel 3: new [direct-tcpip]
debug1: Connection to port 8080 forwarding to 172.17.0.2 port 8888 requested.
debug1: channel 4: new [direct-tcpip]
channel 3: open failed: connect failed: Connection refused
channel 4: open failed: connect failed: Connection refused
debug1: channel 3: free: direct-tcpip: listening port 8080 for 172.17.0.2 port 8888, connect from 127.0.0.1 port 38208 to 127.0.0.1 port 8080, channels 5
debug: channel 4: free: direct-tcpip: listening port 8080 for 172.17.0.2 port 8888, connect from 127.0.0.1 port 38214 to 127.0.0.1 port 8080, channels 4
debug: Connection to port 8080 forwarding to 172.17.0.2 port 8888 requested.
debug1: channel 3: new [direct-tcpip]channel 3: open failed: connect failed: Connection refused
debug: channel 3: free: direct-tcpip: listening port 8080 for 172.17.0.2 port 8888, connect from 127.0.0.1 port 38230 to 127.0.0.1 port 8080, channels 4

Honestly, I did not explicitly set port forwarding when I create the Docker container using docker run. However, what I’m really curious about is how VSCode’s port forwarding works without having to explicitly forward ports like I would normally do in the docker run command. With VSCode, I can instantly access the container’s service without having to restart the Docker container, which seems like magic!

What I’m trying to understand:

  1. Why does VSCode port forwarding work without having to explicitly forward ports or restart the container?
  2. If VSCode’s port forwarding isn’t just simple SSH tunneling, what kind of magic process does VSCode use to make this work?
  3. What did I miss in my attempts with SSH tunneling via terminal? Is there something crucial I’m not doing in my command or Docker setup?

Any insights would be greatly appreciated!

Upvotes: 0

Views: 46

Answers (0)

Related Questions