0%

docker学习笔记之二 起步和入门

docker学习笔记之二 起步和入门

测试Docker版本

1
$ docker --version
2
Docker version 17.12.0-ce, build c97c6d6

运行docker version(不带)或者docker info来获取docker安装的更多信息。

1
$ sudo docker version
2
Client:
3
 Version:	17.12.0-ce
4
 API version:	1.35
5
 Go version:	go1.9.2
6
 Git commit:	c97c6d6
7
 Built:	Wed Dec 27 20:11:14 2017
8
 OS/Arch:	linux/amd64
9
10
Server:
11
 Engine:
12
  Version:	17.12.0-ce
13
  API version:	1.35 (minimum version 1.12)
14
  Go version:	go1.9.2
15
  Git commit:	c97c6d6
16
  Built:	Wed Dec 27 20:09:47 2017
17
  OS/Arch:	linux/amd64
18
  Experimental:	false

测试已安装的Docker

如果运行简单的Docker 镜像(hello-world)来测试你的安装。

1
$ docker run hello-world
2
3
Hello from Docker!
4
This message shows that your installation appears to be working correctly.
5
6
To generate this message, Docker took the following steps:
7
 1. The Docker client contacted the Docker daemon.
8
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
9
    (amd64)
10
 3. The Docker daemon created a new container from that image which runs the
11
    executable that produces the output you are currently reading.
12
 4. The Docker daemon streamed that output to the Docker client, which sent it
13
    to your terminal.
14
15
To try something more ambitious, you can run an Ubuntu container with:
16
 $ docker run -it ubuntu bash
17
18
Share images, automate workflows, and more with a free Docker ID:
19
 https://cloud.docker.com/
20
21
For more examples and ideas, visit:
22
 https://docs.docker.com/engine/userguide/

列出已经下载到你的机器中的hello-world镜像:

1
$ docker image ls
2
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
3
hello-world         latest              f2a91732366c        2 months ago        1.85kB

列出由镜像产生的hello-world容器,当显示消息后就会退出。如果它在运行中,你不需要使用–all选项:

1
$ docker container ls --all
2
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
3
65fbaf599670        hello-world         "/hello"            23 minutes ago      Exited (0) 23 minutes ago                       silly_mclean
4
419dce2f6ec9        hello-world         "/hello"            2 hours ago         Exited (0) 2 hours ago                          eloquent_visvesvaraya

命令总结

1
## 列出 Docker CLI 命令
2
docker
3
docker container --help
4
5
## 显示 Docker 版本和信息
6
docker --version
7
docker version
8
docker info
9
10
## 执行 Docker 镜像
11
docker run hello-world
12
13
## 列出 Docker 镜像
14
docker image ls
15
16
## 理出 Docker 容器 (running, all, all in quiet mode)
17
docker container ls
18
docker container ls -all
19
docker container ls -a -q