zoukankan      html  css  js  c++  java
  • 解决windows系统无法对docker容器进行端口映射的问题

    1、问题:

      在Windows家庭版下安装了docker,并尝试在其中运行jupyter notebook等服务,但映射完毕之后,在主机的浏览器中,打开localhost:port无法访问对应的服务。

    2、问题出现的原因:

    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。

    3、解决方法:

      通过命令

      docker-machine ip default   # 其中,default 是docker-machine的name,可以通过docker-machine -ls 查看

    找到这个Linux的ip地址一般情况下这个地址是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

      

  • 相关阅读:
    iOS应用内支付(内购)的个人开发过程及坑!
    AJAX实现仿Google Suggest效果
    jquery的show/hide性能测试
    如何做到尽可能不使用庞大的jQuery
    CSS3 transition规范的实际使用经验
    jQuery提升性能技巧及个人总结
    使用CSS3实现超炫的Loading(加载)动画效果
    一个有趣的Ajax Hack示范
    使用ajax技术无刷新动态调用股票信息
    将Asp.Net页面输出到EXCEL里去
  • 原文地址:https://www.cnblogs.com/hypnus-ly/p/8683215.html
Copyright © 2011-2022 走看看