Docker for Windows 中文文档(1)——Explore the application and run examples

Get started with Docker for Windows

欢迎来到Docker for Windows!

Docker是用于创建集装箱应用程序的完整开发平台,Docker for Windows是在Windows系统上开始使用Docker的最佳方式。

检查Docker Engine,Compose和Machine的版本

启动您最喜欢的shell(cmd.exe,PowerShell或其他)来检查docker和docker-compose的版本,并验证安装。

C:\Users\rHotD>docker --version
Docker version 17.03.1-ce, build c6d412e

C:\Users\rHotD>docker-compose --version
docker-compose version 1.11.2, build f963d76f

C:\Users\rHotD>docker-machine --version
docker-machine version 0.10.0, build 76ed2a6

浏览应用程序并运行示例

接下来的几个步骤将会介绍一些例子。 这些只是在系统上试验Docker的方法的建议,检查版本信息,并确保docker命令正常工作。

1. 打开一个shell(cmd.exe,PowerShell或其他)。

2. 运行一些Docker命令,例如docker ps,docker版本和docker信息。

这是在powerhell中运行的docker ps的输出。 (在这个例子中,没有容器正在运行。)

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

以下是Docker版本的命令输出示例。

PS C:\Users\Docker> docker version
Client:
Version:      17.03.0-ce
API version:  1.26
Go version:   go1.7.5
Git commit:   60ccb22
Built:        Thu Feb 23 10:40:59 2017
OS/Arch:      windows/amd64

Server:
Version:      17.03.0-ce
API version:  1.26 (minimum version 1.12)
Go version:   go1.7.5
Git commit:   3a232c8
Built:        Tue Feb 28 07:52:04 2017
OS/Arch:      linux/amd64
Experimental: true

以下是docker信息的命令输出示例。

PS C:\Users\Docker> docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.03.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
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 977c511eda0925a723debdc94d09459af49d082a
runc version: a01dafd48bc1c7cc12bdb01206f9fea7dd6feb70
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.12-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934 GiB
Name: moby
ID: BM4O:645U:LUS6:OGMD:O6WH:JINS:K7VF:OVDZ:7NE4:ZVJT:PSMQ:5UA6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 13
 Goroutines: 21
 System Time: 2017-03-02T16:59:13.417299Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

注意:上面的输出是例子。 您的输出,例如docker版本和docker信息,将取决于您的产品版本(例如,在安装较新版本时)。

3. 运行#docker run hello-world来测试从Docker Hub拉一张图像并启动一个容器。

C:\Users\rHotD>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
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.
 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/

4. 尝试更有野心的东西,并使用此命令运行Ubuntu容器。

docker run -it ubuntu bash

这将下载ubuntu容器图像并启动它。 以下是在powerhell中运行此命令的输出。

C:\Users\rHotD>docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
c62795f78da9: Pull complete
d4fceeeb758e: Pull complete
5c9125a401ae: Pull complete
0062f774e994: Pull complete
6b33fd031fac: Pull complete
Digest: sha256:c2bbf50d276508d73dd865cda7b4ee9b5243f2648647d21e3a471dd3cc4209a0
Status: Downloaded newer image for ubuntu:latest
root@a8d217b930ac:/#

键入exit以停止容器并关闭powerhell

5. 使用此命令启动Dockerized Web服务器:

docker run -d -p 80:80 --name webserver nginx

这将下载nginx容器图像并启动它。 以下是在powerhell中运行此命令的输出。

PS C:\Users\jdoe> docker run -d -p 80:80 --name webserver nginx

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx

fdd5d7827f33: Pull complete
a3ed95caeb02: Pull complete
716f7a5f3082: Pull complete
7b10f03a0309: Pull complete
Digest: sha256:f6a001272d5d324c4c9f3f183e1b69e9e0ff12debeb7a092730d638c33e0de3e
Status: Downloaded newer image for nginx:latest
dfe13c68b3b86f01951af617df02be4897184cbf7a8b4d5caf1c3c5bd3fc267f

6. 将您的Web浏览器指向http:// localhost以显示起始页。
(由于您指定了默认HTTP端口,因此无需在URL的末尾追加:80)

这里写图片描述

7. 当您的网络服务器正在运行时运行docker ps,以查看容器上的详细信息。

这里写图片描述

8. 停止或移除容器和图像。
nginx网络服务器将继续在该端口上的容器中运行,直到您停止和/或删除该容器。 如果要停止Web服务器,请键入:docker stop webserver,并使用docker start webserver重新启动它。

要使用单个命令停止并删除正在运行的容器,请键入:docker rm -f webserver。 这将删除容器,而不是nginx映像。 您可以列出本地图像与 docker 图像。 您可能想要保留一些图像,以便您不必再从Docker Hub中拉出。 要删除不再需要的图像,请使用docker rmi,然后使用图像ID或图像名称。 例如,docker rmi nginx

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值