docker - Ping 或 SSH 连接到 docker 容器时出现问题
问题描述
我是码头工人的新手。我在 Windows 10 上安装了 docker。另外,我在我的 win 上安装了 SSH。
我有一个 pylucene 码头集装箱。当我检查我的 docker 容器的状态时,它是 Up。
PS C:\Windows\system32> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d70d6f0ed7ab coady/pylucene "/bin/bash" 4 weeks ago Up 3 hours amazing_dubinsky
此外,我执行它并使用它的 shell 没有问题。
PS C:\Windows\system32> docker exec -it d70d6f0ed7ab /bin/bash
root@d70d6f0ed7ab:/usr/src# python
Python 3.9.2 (default, Mar 31 2021, 12:13:11)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lucene
>>> print(lucene.VERSION)
8.8.1
>>>
但是当我找到它的 IP 并尝试从我的胜利中 ping 这个 docker 容器时,结果只是超时!
PS C:\Windows\system32> docker inspect -f "{{ .NetworkSettings.IPAddress }}" d70d6f0ed7ab
172.17.0.3
PS C:\Windows\system32> ping 172.17.0.3
Pinging 172.17.0.3 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 172.17.0.3:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
PS C:\Windows\system32>
SSH 连接到这个容器也会失败,
PS C:\Windows\system32> ssh root@172.17.0.3
ssh: connect to host 172.17.0.3 port 22: Connection timed out
PS C:\Windows\system32>
解决方案
该coady/pylucene
图像基于python:latest
python:latest
是基于buildpack-deps:buster
buildpack-deps:buster
是基于buildpack-deps:scm
buildpack-deps:scm
是基于buildpack-deps:buster-curl
buildpack-deps:buster-curl
是基于debian:buster
而且... debian 10 默认没有openssh-server
安装/激活。
另外,如此处所述:
Docker Desktop for Windows 无法将流量路由到 Linux 容器。
但是,您可以 ping Windows 容器。
换句话说,您遇到的那些“问题”是完全可以预料的。
推荐阅读
- dart - DataTable - 使可滚动,设置背景颜色和修复/冻结标题行和第一列
- cmake - CMake中两个子目录之间的依赖关系
- javascript - 如何导出带有附加数据的 HTML 表格
- ios - 如何在 iOS 中使用来自 esim 或物理 sim 的移动数据来识别用户
- c# - 如何在动态创建的 Html 表中设置 THEAD 的 CssClass 属性
- java - Java 编辑器软件
- android - 将取决于上下文的变量传递给 AsyncTask 是否安全
- kubernetes - 有没有办法在命名空间之间共享 kubernetes 中的 configMap?
- python - 尝试使用 tkinter 制作一个简单的菜单,但返回“显示无法使用 DPMS”
- c++ - 铸造在 2 种情况下的工作方式不同