1/11
-
Docker 是什么?
Docker 是一个生态,这个生态专注于管理 Containers(容器)。
-
为什么用 Docker?
Docker 使得安装软件与运行软件十分便利。
安装软件时,可能会碰到各种各样的问题,解决这些问题可能会花费很多人力物力。而 Docker 就是想标准化“安装流程”,让用户直接进入运行软件步骤,节省用户成本。
课程中使用安装 Redis 作为例子,来展示普通安装和使用 Docker 启动的效率差别。
-
基础概念
-
Image
Image 也称为镜像,是一个包含运行指定程序的文件系统快照和启动命令的文件。通常在 Docker Hub(https://hub.docker.com/) 下载。
-
Container
Container 也就是容器,是 Image 的一个实例。是一个正在运行的进程,以及机器物理资源的子集。
不同的 Containers 之间,资源是隔离的。
-
Docker Client
用户通过终端与 Docker Client 交互,一个解析用户命令的程序,并发送给 Docker Server。
这个程序本身没有处理 Image 与 Container 的功能。
-
Docker Server
也称之为 Docker Daemon,是负责创建、运行容器的程序。
-
安装
官方下载网站:https://docs.docker.com/get-docker/
注册后安装对应版本。
⚠️注意:安装同时包含了 Linux 虚拟机
-
docker version
安装完成后,在终端输入 docker version,如果输出相关信息说明安装成功了。
-
启动第一个容器
在终端输入 docker run hello-world,之后终端会输出如下信息:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete
Digest: sha256:94ebc7edf3401f299cd3376a1669bc0a49aef92d6d2669005f9bc5ef028dc333
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.
(arm64v8)
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
hello-world 是 Docker 社区维护的一个官方镜像,作用就是演示 Docker 化。
Docker Client 收到终端发来的命令后,检查处理后发送给 Docker Server 来创建容器。创建时会先在本地查找镜像缓存,如果缓存中没有,就会去 Docker Hub 上下载镜像后再继续。

浙公网安备 33010602011771号