|
| 1 | +# Docker 之 Hello World |
| 2 | + |
| 3 | +## 前提 |
| 4 | + |
| 5 | +确保你的环境上已经成功安装 Docker。 |
| 6 | + |
| 7 | +## Hello World 实例 |
| 8 | + |
| 9 | +1. 使用 `docker version` 命令确保你的环境已成功安装 Docker。 |
| 10 | + |
| 11 | +``` |
| 12 | +# docker version |
| 13 | +Client: |
| 14 | + Version: 1.13.1 |
| 15 | + API version: 1.26 |
| 16 | + Package version: <unknown> |
| 17 | + Go version: go1.8.3 |
| 18 | + Git commit: 774336d/1.13.1 |
| 19 | + Built: Wed Mar 7 17:06:16 2018 |
| 20 | + OS/Arch: linux/amd64 |
| 21 | +
|
| 22 | +Server: |
| 23 | + Version: 1.13.1 |
| 24 | + API version: 1.26 (minimum version 1.12) |
| 25 | + Package version: <unknown> |
| 26 | + Go version: go1.8.3 |
| 27 | + Git commit: 774336d/1.13.1 |
| 28 | + Built: Wed Mar 7 17:06:16 2018 |
| 29 | + OS/Arch: linux/amd64 |
| 30 | + Experimental: false |
| 31 | +``` |
| 32 | + |
| 33 | +2. 使用 `docker run` 命令运行 Hello World 镜像。 |
| 34 | + |
| 35 | +``` |
| 36 | +docker run hello-world |
| 37 | +
|
| 38 | +Unable to find image 'hello-world:latest' locally |
| 39 | +latest: Pulling from library/hello-world |
| 40 | +ca4f61b1923c: Pull complete |
| 41 | +Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7 |
| 42 | +Status: Downloaded newer image for hello-world:latest |
| 43 | +
|
| 44 | +Hello from Docker! |
| 45 | +This message shows that your installation appears to be working correctly. |
| 46 | +... |
| 47 | +``` |
| 48 | + |
| 49 | +3. 使用 `docker image ls`命令查看镜像 |
| 50 | + |
| 51 | +``` |
| 52 | +docker image ls |
| 53 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 54 | +docker.io/maven latest 76c9ab5df55b 7 days ago 737 MB |
| 55 | +docker.io/python 2.7-slim 5541369755c4 13 days ago 139 MB |
| 56 | +docker.io/hello-world latest f2a91732366c 4 months ago 1.85 kB |
| 57 | +docker.io/java 8-jre e44d62cf8862 14 months ago 311 MB |
| 58 | +docker.io/training/webapp latest 6fae60ef3446 2 years ago 349 MB |
| 59 | +``` |
| 60 | + |
| 61 | +4. 使用 `docker container ls --all` 命令查看容器 |
| 62 | + |
| 63 | +如果查看正在运行的容器,不需要添加 `--all` 参数。 |
| 64 | + |
| 65 | +``` |
| 66 | +docker container ls --all |
| 67 | +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
| 68 | +a661d957c6fa hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago mystifying_swartz |
| 69 | +3098f24a1064 docker.io/hello-world "/hello" 6 minutes ago Exited (0) 6 minutes ago sad_yonath |
| 70 | +4c98c4f18a39 hello-world "/hello" 8 minutes ago Exited (0) 8 minutes ago admiring_banach |
| 71 | +``` |
0 commit comments