Docker架构图:
我们依照Docker架构图进行Docker基础概念的说明。

Docker是一个Client-Server结构的系统,Docker守护进程运行在主机上,然后通过Socket连接从客户端访问,守护进程从客户端接受命令并管理运行在主机上的容器。容器是一个运行时环境,就好比是我们前面说到的集装箱。
例如架构图中的客户端(Client)和服务端(DOCKER_HOST):
发送命令docker run hello-world
Docker daemon),如下图所示:

Docker客户端和守护进程通过Socket连接,可以远程或本地连接。
Socket说明:网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个
Socket。建立网络通信连接至少要一对端口号(Socket)。Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是用来组织数据的一组接口。
image):Docker镜像类似于虚拟机的镜像,就好比是一个模板,一个面向Docker引擎的只读模板,包含了文件系统,可以通过这个模板来创建容器服务。Ubuntu操作系统环境,可以把它称作一个Ubuntu镜像。镜像也可以安装了Apache应用程序(或其他软件),可以把它称为一个Apache镜像。通过这个镜像可以创建多个容器(最终服务的运行或者项目的运行就是在容器中)。Container):Docker利用容器技术,独立运行一个或者一组应用,通过镜像来创建的。Repository):仓库就是存放镜像的地方。Public)和私有仓库(Private)两种形式。Docker Hub(Docker官方镜像仓库),存放了数量庞大的镜像供用户下载。国内的公开仓库包括阿里云,网易云等镜像仓库,可以提供稳定的国内访问(镜像加速)。push命令,将它上传到指定的公有或则私有仓库。这样用户下次在另一台机器上使用该镜像时,只需将该镜像从仓库pull(拉取)下来就可以了。镜像和容器的关系:

我们以之前运行hello-world镜像为例进行说明。
执行docker run hello-world命令,运行结果如下:
$ sudo docker run hello-world# 出现下面显示,证明运行镜像成功Unable to find image 'hello-world:latest' locally #(本地没有找到hello-world镜像)latest: Pulling(拉取) from library/hello-world #(去远程拉取library/hello-world镜像)1b930d010525: Pull complete #(拉取完成) Digest: sha256:d1668a9a1f5b42ed3f46b70b9cb7c88fd8bdc8a2d73509bb0041cf436018fbf5Status: Downloaded newer image for hello-world:latest#(上面三行是拉取镜像的签名信息)# 总结:由于本地没有hello-world这个镜像,所以会从远程仓库下载一个hello-world的镜像到本地,并创建容器运行。Hello from Docker!#(镜像运行起来了)This message shows that your installation appears to be working correctly.#(此消息表明您的安装似乎可以正常工作。为了生成此消息,Docker采取了以下步骤:)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. (amd64) 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 bashShare 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镜像就会停止运行,容器自动终止。
run命令的执行的流程图:

如下图所示:

Docker与VM对比表:
