Search code examples
dockersshportforwarding

Why doesn't port forwarding work consistently with my Docker instance?


I ssh'd into a server from my laptop. I opened up a port on my laptop to accept incoming traffic from port 9090, and forward it to 9191.

On the server, I created a Docker ball: sudo docker run --network host --runtime=nvidia -it --rm tensorflow/tensorflow:latest-gpu /bin/bash.

Next, on the shell (in Docker), I did this: jupyter notebook --ip=0.0.0.0 --port=9090 --allow-root

Voila! I pointed my browser to http://localhost:9191, and I could see the precious 'lil notebook running.

I exited the Docker ball, quit the ssh process, went home and went to sleep.

Today, I woke up and ssh'd back to the server. I opened up that same port on my laptop as I did the day before.

I accessed a shell in yesterday's Docker image by sudo docker start my_image and then sudo docker exec -it my_image /bin/bash

But now, when I get on the shell (in the Docker), and type jupyter notebook --ip=0.0.0.0 --port=9090 --allow-root, like I did yesterday, my forwarding no longer works. Why?


Solution

  • So, if anyone stumbles onto this question, to solve this I ended up starting over.

    STEP 1: ssh
    STEP 2: create Docker this way: sudo docker run -p 9090:9090 --runtime=nvidia -it --rm tensorflow/tensorflow:latest-gpu /bin/bash

    The key was the -p 9090:9090 part. I don't know what --network host was or wasn't doing, but getting rid of it was the key.