美文网首页Yocto Linux
win10 专业版安装Docker,并在Docker容器中安装u

win10 专业版安装Docker,并在Docker容器中安装u

作者: 小桥流水啦啦啦 | 来源:发表于2019-11-10 10:00 被阅读0次
    1、win10 专业版安装Docker及其Docker setting

    https://docs.docker.com/docker-for-windows/install/

    image.png

    点击Download from Docker Hub

    image.png

    点击Download Docker Desktop for Windows开始下载 Docker Desktop Installer.exe软件。

    下载完成,双击即可安装。

    简单Docker setting:

    image.png image.png image.png image.png image.png image.png
    安装Kitematic:
    image.png

    点击下载Kitematic-windows.zip
    然后解压到Docker安装的目录即可。

    这部分结束

    2、在Docker中安装Ubuntu 18.04

    PS C:\WINDOWS\system32>docker pull ubuntu:18.04
    
    PS C:\WINDOWS\system32> docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    39f14afae918        ubuntu:latest       "/bin/bash"         17 hours ago        Up 3 hours                              ubuntu
    
    PS C:\WINDOWS\system32> docker inspect --format '{{ .NetworkSettings.IPAddress  }}' 39f14afae918
    172.17.0.2
    

    3、windows10配置Docker容器独立IP地址互相通信

    win10专业版,打开powershell,输入ipconfig /all:

    image.png

    打开一个容器,可以看到容器ip地址为自动分配的。

    root@2f45521e73cd:/# ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
            ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
            RX packets 26181  bytes 38007976 (38.0 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 8379  bytes 466623 (466.6 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1  (Local Loopback)
            RX packets 17  bytes 1904 (1.9 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 17  bytes 1904 (1.9 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    当前状态下,通过宿主机是无法ping通的。

    PS C:\WINDOWS\system32> ping 172.17.0.2
    
    正在 Ping 172.17.0.2 具有 32 字节的数据:
    请求超时。
    请求超时。
    请求超时。
    请求超时。
    
    172.17.0.2 的 Ping 统计信息:
        数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失),
    
    通过配置路由表实现ip互通

    查看route print -4

    image.png

    查看docker的ip地址配置:


    image.png
    暴露给宿主机的为10.0.75.1

    添加路由

    route -p add 172.17.0.0 MASK 255.255.255.0 10.0.75.2

    image.png

    重新ping容器地址:


    image.png
    现在则可以直接通过ip访问。
    由于docker默认采用bridge网络,每次容器启动时自动分配ip,我们可以创建自己的网络bridge1,在创建容器时指定ip,如需独立ip访问则另外增加路由。

    route -p add 172.18.12.0 MASK 255.255.255.0 10.0.75.2

    如果删除路由:

    route delete 172.18.12.0

    No pain, no gain!
    Time and tide wait for no man!

    相关文章

      网友评论

        本文标题:win10 专业版安装Docker,并在Docker容器中安装u

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