|
@ -102,9 +102,46 @@ hello from busybox |
|
|
|
|
|
|
|
|
### 二) 熟悉Docker指令 |
|
|
### 二) 熟悉Docker指令 |
|
|
|
|
|
|
|
|
|
|
|
#### 让我们来尝试不同的**docker command** |
|
|
|
|
|
|
|
|
|
|
|
#### 1. docker ps |
|
|
|
|
|
|
|
|
|
|
|
> **docker ps** 命令可以查看当前正在运行的所有容器的状态,包括`CONTAINER ID`、`IMAGE`、`COMMAND`、`CREATE (创建时间)`、`STATUS (容器状态)` |
|
|
|
|
|
|
|
|
|
|
|
#### 让我们查看目前有哪些容器正在运行 |
|
|
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
|
$ docker ps |
|
|
|
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
#### 可以看到控制台输出了了一个空的列表,这是正常的,因为目前没有容器正在运行。如果需要查看包括不在运行的所有容器,我们可以加入 **-a** 参数 |
|
|
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
|
$ docker ps -a |
|
|
|
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS |
|
|
|
|
|
305297d7a235 busybox "uptime" 11 minutes ago Exited ( |
|
|
|
|
|
ff0a5c3750b9 busybox "sh" 12 minutes ago Exited ( |
|
|
|
|
|
14e5bd11d164 hello-world "/hello" 2 minutes ago Exited ( |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
#### Wow~ 之前运行过的容器全部都出现在输出中了~ |
|
|
|
|
|
|
|
|
|
|
|
#### 2. docker run -it |
|
|
|
|
|
|
|
|
|
|
|
> **docker run -it** 可以在我们创建 **container** 的同时,以交互式的形式获取到 **container shell** 的控制权 |
|
|
|
|
|
|
|
|
|
|
|
#### 接下来我们使用 **run -it** 命令来创建一个 `busybox container`: |
|
|
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
|
$ docker run -it busybox sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/ # ls |
|
|
|
|
|
bin dev etc home proc root sys tmp usr var |
|
|
|
|
|
/ # uptime |
|
|
|
|
|
05:45:21 up 5:58, 0 users, load average: 0.00, 0.01, 0.04 |
|
|
|
|
|
``` |
|
|
|
|
|
|