美文网首页
Windows安装Docker

Windows安装Docker

作者: 明训 | 来源:发表于2021-03-17 01:33 被阅读0次

    环境依赖

    windows10之前:安装Docker Toolbox,Dockbox Toolbox使用Oracle Virtual Box而不是Hyper-V

    windows10:使用Hyper-V

    启用Hyper-V

    打开控制面板 - 程序和功能 - 启用或关闭Windows功能,勾选Hyper-V,然后点击确定即可

    CPU开启虚拟机

    ctrl+alt+delte,选择任务管理器,然后选中性能标签,然后选中CPU,然后查看虚拟化是否启用,确保状态为已启用

    安装docker for Windows

    Docker下载地址为:https://store.docker.com/editions/community/docker-ce-desktop-windows 即可下载安装包,在安装过程中会重启电脑,这点需要注意,注意防止数据丢失。

    https://www.cnblogs.com/5bug/p/8506085.html

    启动docker

    在桌面找到Docker for Windows快捷方式,双击启动即可!启动成功后托盘处会有一个小鲸鱼的图标。打开命令行输入命令:docker version可以查看当前docker版本号

    查看版本

    C:\Users\Administrator>docker version
    Client:
     Version:           18.06.1-ce
     API version:       1.38
     Go version:        go1.10.3
     Git commit:        e68fc7a
     Built:             Tue Aug 21 17:21:34 2018
     OS/Arch:           windows/amd64
     Experimental:      false
    
    Server:
     Engine:
      Version:          18.06.1-ce
      API version:      1.38 (minimum version 1.12)
      Go version:       go1.10.3
      Git commit:       e68fc7a
      Built:            Tue Aug 21 17:29:02 2018
      OS/Arch:          linux/amd64
      Experimental:     false
    
    C:\Users\Administrator>
    

    配置国内镜像

    https://jingyan.baidu.com/article/1876c8525ad73c890a137673.html

    {
      "registry-mirrors": [
        "https://b7j3uwrc.mirror.aliyuncs.com"
      ]
    }
    

    hello-world镜像

    通过输入docker pull hello-world来拉取hello-world镜像

    C:\Users\Administrator>docker run hello-world
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/
    
    
    C:\Users\Administrator>
    

    若是出现了上诉的内容则说明hello-world运行成功。

    配置文件

    C:\Users\Administrator.docker\daemon.json

    https://blog.csdn.net/u013948858/article/details/80811986

    镜像位置

    镜像文件是存储在虚拟硬盘上,虚拟硬盘的位置为C:\Users\Public\Documents\Hyper-V\Virtual hard disks

    https://blog.csdn.net/OnedayIlove/article/details/100556555

    使用范例

    tomat镜像

    C:\Users\Administrator>docker run   tomcat  -p8080:8080
    docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"-p8080:8080\": executable file not found in $PATH": unknown.
    
    C:\Users\Administrator>
    

    解决: 将-p前移即可.

    C:\Users\Administrator>docker run -p8080:8080  tomcat
    11-Dec-2019 14:41:08.262 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/8.5.49
    11-Dec-2019 14:41:08.288 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Nov 17 2019 18:45:30 UTC
    11-Dec-2019 14:41:08.288 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 8.5.49.0
    11-Dec-2019 14:41:08.288 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux 
    

    镜像删除

    C:\Users\Administrator>docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    
    C:\Users\Administrator>docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tomcat              latest              6408fdc94212        2 weeks ago         507MB
    hello-world         latest              fce289e99eb9        11 months ago       1.84kB
    gcplot/gcplot       latest              6f2d2b5fffc8        23 months ago       1.03GB
    
    C:\Users\Administrator>docker rmi -f 6f2d2b5fffc8
    Untagged: gcplot/gcplot:latest
    Untagged: gcplot/gcplot@sha256:911225b14e3e964f8e6e60526ff823e5711a20f009728c7568ba2e3946e11530
    Deleted: sha256:6f2d2b5fffc8a24465febdf97b7f6f46a0c5c7a35e55619b8f4776a44de95ea5
    
    C:\Users\Administrator>
    

    镜像导出

    把镜像存出到本地文件,可以使用docker save命令

    C:\Users\Administrator>docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tomcat              latest              6408fdc94212        2 weeks ago         507MB
    hello-world         latest              fce289e99eb9        11 months ago       1.84kB
    gcplot/gcplot       latest              6f2d2b5fffc8        23 months ago       1.03GB
    C:\Users\Administrator>docker save -o C:\images\gcplot.tar gcplot/gcplot:latest
    

    docker save –o /data/testimage.tar testimage:latest

    载入镜像

    C:\Users\Administrator>docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tomcat              latest              6408fdc94212        2 weeks ago         507MB
    hello-world         latest              fce289e99eb9        11 months ago       1.84kB
    
    C:\Users\Administrator>docker load --input C:\images\gcplot.tar
    Loaded image: gcplot/gcplot:latest
    
    C:\Users\Administrator>docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tomcat              latest              6408fdc94212        2 weeks ago         507MB
    hello-world         latest              fce289e99eb9        11 months ago       1.84kB
    gcplot/gcplot       latest              6f2d2b5fffc8        23 months ago       1.03GB
    
    C:\Users\Administrator>
    

    相关文章

      网友评论

          本文标题:Windows安装Docker

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