You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何连接运行在远程Docker容器中的Jupyter Notebook?

Fixing Connection Refused for Dockerized Jupyter Notebook on Remote AWS Instance

Let's break down why you're hitting that "Connection refused" error and walk through the fixes step by step:

The Core Problem

When you start Jupyter inside the container with just --port=8884, it defaults to binding only to the container's local loopback (127.0.0.1). Even though you've mapped the remote machine's port 8884 to the container's 8884, the remote machine's 127.0.0.1 is a separate network namespace from the container's. That means your SSH tunnel can't reach the Jupyter instance running inside the container.

Step-by-Step Solutions

1. Update Jupyter's Listening Address in the Container

Modify your Jupyter startup command to bind to all network interfaces in the container using --ip=0.0.0.0. This lets the Docker port mapping connect to the Jupyter instance properly:

jupyter-notebook --NotebookApp.iopub_data_rate_limit=10000000000 --no-browser --port=8884 --allow-root --ip=0.0.0.0

2. Verify Port Mapping and Listening States

  • On the remote machine, check if Docker is correctly forwarding port 8884:

    netstat -tulpn | grep 8884
    

    You should see a line like 0.0.0.0:8884 linked to the docker-proxy process—this confirms the remote machine is listening for connections on that port.

  • Inside the container, confirm Jupyter is listening on all interfaces:

    1. Grab your container ID first: docker ps
    2. Enter the container: docker exec -it <container-id> bash
    3. Run: netstat -tulpn | grep 8884
      You should see 0.0.0.0:8884 associated with the Jupyter Python process.

3. Ensure Your SSH Tunnel is Active

Your SSH LocalForward only works while the SSH session is running. If you want to keep it alive in the background, add -fN when connecting:

ssh -fN p3

4. Test the Connection

Once all the above is set up, open your local browser and navigate to http://localhost:8883. You'll need to enter the Jupyter token (printed in the container's terminal when you start the notebook) or a pre-configured password to access it.

Troubleshooting If It Still Fails

  • Check for port conflicts: If another process on the remote machine is using port 8884, switch to a different port. For example:
    • Update your SSH config to LocalForward 8883 127.0.0.1:8885
    • Restart the container with nvidia-docker run -it -p 8885:8885 <docker image>
    • Start Jupyter inside the container with --port=8885
  • Double-check firewall settings: Ensure the remote machine's firewall isn't blocking incoming connections on port 8884 (though since you can access non-containerized Jupyter, this is less likely to be the issue).

内容的提问来源于stack exchange,提问作者avitheavi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:31:57