解决无法对docker容器进行端口映射的问题
来源:互联网 发布:超星数据库 编辑:程序博客网 时间:2024/06/10 19:26
在安装了一个Windows下安装了docker,并尝试在其中运行Nginx、owncloud等服务,但映射完毕之后,在主机的浏览器中,打开localhost:port无法访问对应的服务。
用百度尝试了下,始终找不到答案,难道这个问题大家都没遇到过么?于是使用Google,并用英文检索,一会就找到了对应的答案。
The reason you’re having this, is because on Linux, the docker daemon (and your containers) run on the Linux machine itself, so “localhost” is also the host that the container is running on, and the ports are mapped to.
On Windows (and OS X), the docker daemon, and your containers cannot run natively, so only the docker client is running on your Windows machine, but the daemon (and your containers) run in a VirtualBox Virtual Machine, that runs Linux.
原来,docker是运行在Linux上的,在Windows中运行docker,实际上还是在Windows下先安装了一个Linux环境,然后在这个系统中运行的docker。也就是说,服务中使用的localhost指的是这个Linux环境的地址,而不是我们的宿主环境Windows。我们可以通过命令
docker-machine ip default
找到这个Linux的ip地址,一般情况下这个地址是192.168.99.100,然后在Windows的浏览器中,输入这个地址,加上服务的端口即可启用了。
比如,我在docker中运行了一个nginx的服务,启动命令
docker run -d -p 8888:80 hub.c.163.com/public/nginx:1.2.1
最后,在浏览器中测试即可看到结果:
- 解决无法对docker容器进行端口映射的问题
- Docker容器的端口映射
- 理解Docker容器端口映射
- 解决 docker 容器的中文乱码问题
- docker端口映射失败解决
- Docker-端口映射实现访问容器
- docker使用mysql时的端口映射问题
- 016-docker容器与宿主机的端口映射
- 使用 docker 对容器资源进行限制
- 云计算之路-阿里云上-容器难容:自建docker swarm集群遭遇无法解决的问题
- 解决无法docker镜像无法上传的问题
- eclipse无法对某些函数进行代码提示的问题的解决
- docker 给运行中的容器设置端口映射
- docker--端口映射与容器互联
- 解决docker容器内时间不同步问题
- 解决docker镜像无法下载的问题
- 解决普通用户无法使用docker命令的问题
- 解决docker镜像无法下载的问题
- 欢迎使用CSDN-markdown编辑器
- Leetcode-Unique Paths(dp)
- 百度2017秋招笔试编程题
- 多重循环及数组
- 多线程2
- 解决无法对docker容器进行端口映射的问题
- HP ALM/ CAST AIP助Devops落地?
- JAVA中内部类(匿名内部类)访问的局部变量为什么要用final修饰?
- 类的方法
- Java IO流
- Kubernetes(K8S)
- MySQL索引知识总结
- C# mongo-csharp-driver 2.4.4权限 身份登录
- sqlserver基本操作