镜像配置 — 加速

[toc]

image-20220508205850357

每一个开发者都有一个唯一的加速器地址

安装/升级Docker客户端

推荐安装1.10.0以上版本的Docker客户端,参考文档docker-ceopen in new window

配置镜像加速器

针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ks0realz.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

重新启动docker

验证

docker run hello-word

如果本地没有hello-word这个镜像,就会下载一个hello-word镜像,并且在本地容器内运行

而且输出提示信息后,hello-word就会停止运行,容器自动终止

run做了些什么

  1. 开始docker先在本机中寻找镜像以该镜像为模板生产容器实例运行
  2. 如果没有的话就去docker hub上查找镜像,找到就下载到本地并且以该镜像为模板生产容器实例运行
  3. 如果没有找到就报错,返回错误

为什么docker比虚拟机快

因为docker不需要像hypervisor(虚拟机)实现硬件实例化,运行在docker容器上的程序直接使用的都是实例物理机的硬件资源,因此在CPU、内存利用率上docker更有效率

hello-word案例

root@ubuntu:/hyerledgerFabric# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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.
    (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 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/

root@ubuntu:/hyerledgerFabric# docker run hello-world

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.
    (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 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/