[英]Docker-compose can't connect to jupyter notebook on WSL
I run docker-compose on my WSL with a jupyter notebook, it gives me following information:我用 jupyter notebook 在我的 WSL 上运行 docker-compose,它给了我以下信息:
[I 00:28:20.921 NotebookApp] Jupyter Notebook 6.1.3 is running at:
[I 00:28:20.921 NotebookApp] http://docker-desktop:3000/?token=...
[I 00:28:20.921 NotebookApp] or http://127.0.0.1:3000/?token=...
[I 00:28:20.921 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
as docker is running on WSL I can't access it via localhost on my windows machine.由于 docker 在 WSL 上运行,我无法通过 windows 机器上的 localhost 访问它。 I looked up the ip of the network adapter which is 172.23.16.1 and tried to access the notebook via 172.23.16.1:3000, but I get an error connection refused.
我查找了 172.23.16.1 的网络适配器的 ip 并尝试通过 172.23.16.1:3000 访问笔记本,但我收到错误连接被拒绝。
I also opened incoming and outgoing port 3000 on my windows machine我还在我的 windows 机器上打开了传入和传出端口 3000
What have I missed?我错过了什么?
Have you map your container port so the host machine can reach?你有你的容器端口 map 以便主机可以到达吗?
Another common problem is: by default jupiter notebook will only allow traffic coming from localhost
(notice that this localhost
is the container itself), therefore you can't access from anywhere outside of the container.另一个常见问题是:默认情况下,jupiter notebook 将只允许来自
localhost
的流量(请注意,此localhost
是容器本身),因此您无法从容器外的任何地方访问。 So to resolve this, make sure you start jupiter notebook and allow traffic coming from all IPs:因此,要解决此问题,请确保启动 jupiter notebook 并允许来自所有 IP 的流量:
jupyter notebook --ip 0.0.0.0
Long story short, you are almost certainly running into the same problem documented in this , this , and this question, among others.长话短说,您几乎肯定会遇到this 、 this和this question 等中记录的相同问题。 The last one is most similar, since it is about accessing a WSL2 instance from a Docker container, but they are all the same root cause.
最后一个最相似,因为它是关于从 Docker 容器访问 WSL2 实例,但它们都是相同的根本原因。 To quote my answer (slightly modified) from one of those:
从其中之一引用我的答案(稍作修改):
The core issue here is that WSL2 operates in a Hyper-V VM with its own virtual NIC, running NAT'd behind the Windows host.这里的核心问题是 WSL2 在具有自己的虚拟 NIC 的 Hyper-V VM 中运行,在 Windows 主机后面运行 NAT。 WSL1, on the other hand, ran bridged with the Windows NIC.
另一方面,WSL1 与 Windows NIC 桥接。
On localhost, Windows does seem to do an automatic mapping, but for the host IP address (and thus, on the local network - Including Docker containers, since they are on their own network), it does not.在 localhost 上,Windows 似乎确实进行了自动映射,但对于主机 IP 地址(因此,在本地网络上 - 包括 Docker 容器,因为它们不在自己的网络上)。 Even with the Docker network in bridged mode, it still does not see the WSL2 IP without additional effort.
即使 Docker 网络处于桥接模式,它仍然没有额外的努力就看不到 WSL2 IP。
You'll find a lot of information on this particular topic on this Github thread , along with several workarounds that I documented in answers to the other questions.您将在此Github 线程中找到有关此特定主题的大量信息,以及我在其他问题的答案中记录的几种解决方法。
In your case, I would propose running the Jupyter notebook in a WSL1 instance, rather than WSL2.在您的情况下,我建议在 WSL1 实例而不是 WSL2 中运行 Jupyter 笔记本。 To my knowledge, there's nothing special in Jupyter which would require WSL2 capabilities, right?
据我所知,Jupyter 没有什么特别需要 WSL2 功能的,对吧?
Again, with a copy/paste here -- You can convert the WSL2 instance to WSL1 by either doing (from PowerShell) a wsl --set-version <distroname> 1
or by cloning the existing with a wsl --export <distroname> <archivename>.tar
and then wsl --import <distroname> <installlocation) <archivename>.tar
.同样,在这里复制/粘贴 - 您可以通过(从 PowerShell)执行
wsl --set-version <distroname> 1
或使用wsl --export <distroname> <archivename>.tar
克隆现有实例,将 WSL2 实例转换为 WSL1 wsl --export <distroname> <archivename>.tar
然后wsl --import <distroname> <installlocation) <archivename>.tar
。 I prefer cloning since it gives you a backup.我更喜欢克隆,因为它可以为您提供备份。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.