一、问题:docker
在Windows家庭版下安装了docker,并尝试在其中运行jupyter notebook等服务,但映射完毕以后,在主机的浏览器中,打开localhost:port没法访问对应的服务。windows
二、问题出现的缘由:浏览器
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.app
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。this
三、解决方法:spa
经过命令code
docker-machine ip default #
ip其中,
default 是docker-machine的name,能够经过docker-machine -ls 查看
找到这个Linux的ip地址,
ci通常状况下这个地址是192.168.99.100,而后在Windows的浏览器中,输入这个地址,加上服务的端口便可启用了。
好比,首先运行一个docker 容器:
docker run -it -p 8888:8888 conda:v1
其中,conda:v1是个人容器名称。而后在容器中开启jupyter notebook 服务:
jupyter notebook --no-browser --port=8888 --ip=172.17.0.2 --allow-root
其中的ip参数为个人容器的ip地址,能够经过以下命令得到:
docker inspect container_id
最后在windows浏览器中测试结果:
http://192.168.99.100:8888