jon*_*way 8 networking port port-forwarding mac-osx docker
我拉了一个 Docker 镜像:
$ docker pull ghost
Run Code Online (Sandbox Code Playgroud)
并从图像运行一个容器:
$ docker run --name test-ghost -p 8080:2368 -d ghost
7d984e974f6a75fe18b3d397b5c8f0a428928a2be9df83f0d61a679aa5f537fc
Run Code Online (Sandbox Code Playgroud)
我的理解是,-p交换机会将主机上的端口 (8080) 映射到 Docker 内部的端口 (2368),以便我可以从 Docker 外部(即从我的主机)访问在 Docker 内运行的 Web 服务器。
但是,当我尝试从我的主机浏览 Chrome 中的以下任何地址时:
http://localhost:8080/
http://0.0.0.0:8080/
http://127.0.0.1:8080/
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
This webpage is not available
ERR_CONNECTION_REFUSED
Run Code Online (Sandbox Code Playgroud)
这似乎可能是连接问题,而不是容器内部的问题,因为当我检查容器内部正在运行的进程时,似乎 NodeJS 正在运行:
$ docker top test-ghost
UID PID PPID ... CMD
docker 4290 1028 ... npm
docker 4324 4290 ... sh -c node index
docker 4325 4324 ... node index
Run Code Online (Sandbox Code Playgroud)
但似乎没有在端口 8080 上侦听:
$ sudo lsof -n -i4TCP:8080 | grep LISTEN
$
Run Code Online (Sandbox Code Playgroud)
我还检查了我的 MacOS 防火墙已关闭。
我不希望这里有完整的解决方案,因为我知道我提供的信息很少。
我想知道的是,人们将如何解决这样的问题?
Docker 端口似乎无法访问。
有没有办法找出端口映射不起作用的原因?或者有什么端口都被码头工人暴露?也许我映射了错误的内部端口?
或者对于我在这里可能做错了什么,还有其他一般性建议吗?
终于想出了如何使这项工作!
我在 MacOS 上运行 Docker 并使用“Docker QuickStart Terminal”。
事实证明,导航到“localhost”、“127.0.0.1”等是错误的,因为看起来 Docker 设置了自己的主机:
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com
Run Code Online (Sandbox Code Playgroud)
当我使用192.168.99.100上面给出的时,一切正常。
| 归档时间: |
|
| 查看次数: |
23928 次 |
| 最近记录: |