美文网首页
Win10上使用Docker【二】

Win10上使用Docker【二】

作者: 半个王国 | 来源:发表于2017-12-03 19:16 被阅读132次

    常用操作

    查看版本

    PS C:\Users\HD> docker version
    Client:
     Version:      17.09.0-ce
     API version:  1.32
     Go version:   go1.8.3
     Git commit:   afdb6d4
     Built:        Tue Sep 26 22:40:09 2017
     OS/Arch:      windows/amd64
    
    Server:
     Version:      17.09.0-ce
     API version:  1.32 (minimum version 1.12)
     Go version:   go1.8.3
     Git commit:   afdb6d4
     Built:        Tue Sep 26 22:45:38 2017
     OS/Arch:      linux/amd64
     Experimental: true
    
    
    PS C:\Users\HD> docker-compose version
    docker-compose version 1.16.1, build 6d1ac219
    docker-py version: 2.5.1
    CPython version: 2.7.13
    OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
    
    
    PS C:\Users\HD> docker-machine version
    docker-machine.exe version 0.12.2, build 9371605
    

    查看docker配置详情

    PS C:\Users\HD> docker info
    Containers: 0
     Running: 0
     Paused: 0
     Stopped: 0
    Images: 0
    Server Version: 17.09.0-ce
    Storage Driver: overlay2
     Backing Filesystem: extfs
     Supports d_type: true
     Native Overlay Diff: true
    Logging Driver: json-file
    Cgroup Driver: cgroupfs
    Plugins:
     Volume: local
     Network: bridge host ipvlan macvlan null overlay
     Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
    Swarm: inactive
    Runtimes: runc
    Default Runtime: runc
    Init Binary: docker-init
    containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
    runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
    init version: 949e6fa
    Security Options:
     seccomp
      Profile: default
    Kernel Version: 4.9.49-moby
    Operating System: Alpine Linux v3.5
    OSType: linux
    Architecture: x86_64
    CPUs: 2
    Total Memory: 1.934GiB
    Name: moby
    ID: NT5B:UFPG:2QMO:ZVDJ:T5KH:J3WW:6NQX:6GXV:YDCG:GYPO:V2ZR:WAHP
    Docker Root Dir: /var/lib/docker
    Debug Mode (client): false
    Debug Mode (server): true
     File Descriptors: 16
     Goroutines: 25
     System Time: 2017-12-03T07:45:16.3582305Z
     EventsListeners: 0
    Registry: https://index.docker.io/v1/
    Experimental: true
    Insecure Registries:
     127.0.0.0/8
    Live Restore Enabled: false
    

    查看已创建容器

    PS C:\Users\HD> docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    

    我这里没有数据,是因为刚刚部署好环境,还没有创建过

    拉取 hello-world 镜像并运行一个容器

    执行命令:docker run hello-world ,会默认从Docker Hub拉去镜像 hello-world,并使用该镜像运行一个容器

    PS C:\Users\HD> docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    ca4f61b1923c: Pull complete
    Digest: sha256:150f6d05b8898b79f55114991c01b89688a02dab6115e402b7855792a440caff
    Status: Downloaded newer image for hello-world:latest
    
    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://cloud.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/
    

    运行一个 Ubuntu 容器

    PS C:\Users\HD> docker run -it ubuntu bash
    Unable to find image 'ubuntu:latest' locally
    latest: Pulling from library/ubuntu
    660c48dd555d: Pull complete
    4c7380416e78: Pull complete
    421e436b5f80: Pull complete
    e4ce6c3651b3: Pull complete
    be588e74bd34: Pull complete
    Digest: sha256:7c67a2206d3c04703e5c23518707bdd4916c057562dd51c74b99b2ba26af0f79
    Status: Downloaded newer image for ubuntu:latest
    // 进入容器里面,执行命令 ls
    root@afc658251a9c:/# ls
    bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    

    上面的命令下载并启动了 ubuntu 容器镜像

    启动一个容器化的 Nginx 服务器

    PS C:\Users\HD> docker run -d -p 80:80 --name webserver nginx
    Unable to find image 'nginx:latest' locally
    latest: Pulling from library/nginx
    bc95e04b23c0: Pull complete
    f3186e650f4e: Pull complete
    9ac7d6621708: Pull complete
    Digest: sha256:b81f317384d7388708a498555c28a7cce778a8f291d90021208b3eba3fe74887
    Status: Downloaded newer image for nginx:latest
    4c0a14eae6bd2fa2f5e93d391118c79d4fe9d0fa9ac08b4ac45964a694aa19cb
    

    通过浏览器访问 80 端口,即可看到刚刚启动的 nginx


    image.png

    查看当前已创建的容器

    PS C:\Users\HD> docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
    4c0a14eae6bd        nginx               "nginx -g 'daemon ..."   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   webservers
    

    停止/删除 容器/镜像

    上一步启动的 nginx 服务器,在你停止或移除这个容器前,会一直在80端口运行下去

    停止命令:docker stop webserver
    启动命令:docker start webserver.

    停止并移除容器命令:docker rm -f webserver

    查看镜像

    查看本地镜像:docker images

    PS C:\Users\HD> docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    nginx               latest              9e7424e5dbae        10 days ago         108MB
    hello-world         latest              f2a91732366c        12 days ago         1.85kB
    ubuntu              latest              20c44cd7596f        2 weeks ago         123MB
    

    删除本地镜像:docker rmi <image ID | image name>
    删除nginx镜像:docker rmi nginx

    相关文章

      网友评论

          本文标题:Win10上使用Docker【二】

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