美文网首页Docker容器
非 Win10 企业版 Docker 运行 nginx 端口映射

非 Win10 企业版 Docker 运行 nginx 端口映射

作者: Mr张巍瀚 | 来源:发表于2017-10-16 21:29 被阅读0次

问题描述

在 Docker 中启动Nginx服务并将端口映射到主机8089端口,

$ docker run -d -p 8090:80 nginx

此时在主机浏览器访问localhost:8090是无法正常显示的

5d1f1fa451ed42d0be768b1576b4129d-10.png

问题原因

由于在非win10企业版中使用的Docker都是先由VirtualBox虚拟一个Linux环境然后Docker运行在这个虚拟环境里,所以localhost是对于docker镜像对虚拟的Linux环境来说的,端口映射在了虚拟的Linux中。

问题解决

使用 docker-machine ip default查看虚拟Linux提供给主机的IP地址,其实在Docker启动时就有IP提示

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

此时我们在浏览器中把localhost换成刚才的IP地址就能正常访问Nginx默认页了。


cd6d322673d446db85bf1820a6bf8f7d-11.png

建议

Docker是在Ubuntu下诞生的,所以尽可能使用Ubuntu系统,搞这些东西Windows真的不适合。

相关文章

网友评论

    本文标题:非 Win10 企业版 Docker 运行 nginx 端口映射

    本文链接:https://www.haomeiwen.com/subject/mkwluxtx.html