服务器 > 服务器 > 云虚拟主机

Docker安装配置镜像加速器的实现

22人参与 2025-02-14 云虚拟主机

1.配置yum源仓库

[root@localhost ~]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
  % total    % received % xferd  average speed   time    time     time  current
                                 dload  upload   total   spent    left  speed
100  1919  100  1919    0     0   2357      0 --:--:-- --:--:-- --:--:--  2357
[root@localhost ~]# sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo
[root@localhost ~]# mv docker-ce.repo /etc/yum.repos.d/
[root@localhost ~]# dnf -y install docker-ce

2.安装docker

[root@localhost ~]# dnf -y install docker-ce
正在更新 subscription management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

docker ce stable - x86_64                                                     18 kb/s |  56 kb     00:03    
上次元数据过期检查:0:00:01 前,执行于 2024年09月11日 星期三 09时42分01秒。
依赖关系解决。
=============================================================================================================
 软件包                             架构            版本                     仓库                       大小
=============================================================================================================
安装:
 docker-ce                          x86_64          3:27.2.1-1.el9           docker-ce-stable           27 m
安装依赖关系:
 containerd.io                      x86_64          1.7.21-3.1.el9           docker-ce-stable           43 m
 docker-ce-cli                      x86_64          1:27.2.1-1.el9           docker-ce-stable          8.0 m
安装弱的依赖:
 docker-buildx-plugin               x86_64          0.16.2-1.el9             docker-ce-stable           14 m
 docker-ce-rootless-extras          x86_64          27.2.1-1.el9             docker-ce-stable          4.4 m
 docker-compose-plugin              x86_64          2.29.2-1.el9             docker-ce-stable           13 m

事务概要
=============================================================================================================
安装  6 软件包

总下载:109 m
安装大小:425 m
下载软件包:
(1/6): docker-ce-27.2.1-1.el9.x86_64.rpm                                     7.0 mb/s |  27 mb     00:03    
(2/6): containerd.io-1.7.21-3.1.el9.x86_64.rpm                               7.6 mb/s |  43 mb     00:05    
(3/6): docker-ce-cli-27.2.1-1.el9.x86_64.rpm                                 3.4 mb/s | 8.0 mb     00:02    
(4/6): docker-ce-rootless-extras-27.2.1-1.el9.x86_64.rpm                     4.8 mb/s | 4.4 mb     00:00    
(5/6): docker-buildx-plugin-0.16.2-1.el9.x86_64.rpm                          1.8 mb/s |  14 mb     00:07    
(6/6): docker-compose-plugin-2.29.2-1.el9.x86_64.rpm                         7.6 mb/s |  13 mb     00:01    
-------------------------------------------------------------------------------------------------------------
总计                                                                          14 mb/s | 109 mb     00:07     
docker ce stable - x86_64                                                    2.3 kb/s | 1.6 kb     00:00    
导入 gpg 公钥 0x621e9f35:
 userid: "docker release (ce rpm) <docker@docker.com>"
 指纹: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 来自: https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                              1/1 
  安装    : docker-compose-plugin-2.29.2-1.el9.x86_64                                                    1/6 
  运行脚本: docker-compose-plugin-2.29.2-1.el9.x86_64                                                    1/6 
  安装    : docker-buildx-plugin-0.16.2-1.el9.x86_64                                                     2/6 
  运行脚本: docker-buildx-plugin-0.16.2-1.el9.x86_64                                                     2/6 
  安装    : docker-ce-cli-1:27.2.1-1.el9.x86_64                                                          3/6 
  运行脚本: docker-ce-cli-1:27.2.1-1.el9.x86_64                                                          3/6 
  安装    : containerd.io-1.7.21-3.1.el9.x86_64                                                          4/6 
  运行脚本: containerd.io-1.7.21-3.1.el9.x86_64                                                          4/6 
  安装    : docker-ce-rootless-extras-27.2.1-1.el9.x86_64                                                5/6 
  运行脚本: docker-ce-rootless-extras-27.2.1-1.el9.x86_64                                                5/6 
  安装    : docker-ce-3:27.2.1-1.el9.x86_64                                                              6/6 
  运行脚本: docker-ce-3:27.2.1-1.el9.x86_64                                                              6/6 
  验证    : containerd.io-1.7.21-3.1.el9.x86_64                                                          1/6 
  验证    : docker-buildx-plugin-0.16.2-1.el9.x86_64                                                     2/6 
  验证    : docker-ce-3:27.2.1-1.el9.x86_64                                                              3/6 
  验证    : docker-ce-cli-1:27.2.1-1.el9.x86_64                                                          4/6 
  验证    : docker-ce-rootless-extras-27.2.1-1.el9.x86_64                                                5/6 
  验证    : docker-compose-plugin-2.29.2-1.el9.x86_64                                                    6/6 
已更新安装的产品。

已安装:
  containerd.io-1.7.21-3.1.el9.x86_64                     docker-buildx-plugin-0.16.2-1.el9.x86_64           
  docker-ce-3:27.2.1-1.el9.x86_64                         docker-ce-cli-1:27.2.1-1.el9.x86_64                
  docker-ce-rootless-extras-27.2.1-1.el9.x86_64           docker-compose-plugin-2.29.2-1.el9.x86_64          

完毕!

3.启动docker

1.启动docker自动开机

[root@localhost ~]# systemctl enable --now docker
created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

2.查看docker的当前状态

[root@localhost ~]# systemctl status docker
● docker.service - docker application container engine
     loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled)
     active: active (running) since wed 2024-09-11 09:43:49 cst; 17s ago
triggeredby: ● docker.socket
       docs: https://docs.docker.com
   main pid: 35124 (dockerd)
      tasks: 10
     memory: 25.6m
        cpu: 787ms
     cgroup: /system.slice/docker.service
             └─35124 /usr/bin/dockerd -h fd:// --containerd=/run/containerd/containerd.sock

9月 11 09:43:48 localhost.localdomain systemd[1]: starting docker application container engine...
9月 11 09:43:48 localhost.localdomain dockerd[35124]: time="2024-09-11t09:43:48.495682747+08:00" level=info >
9月 11 09:43:48 localhost.localdomain dockerd[35124]: time="2024-09-11t09:43:48.587274179+08:00" level=info >
9月 11 09:43:49 localhost.localdomain dockerd[35124]: time="2024-09-11t09:43:49.349750672+08:00" level=info >
...

4.配置镜像加速器

1.进入vim文字编辑器

vim /etc/docker/daemon.json

2.编辑内容在阿里云官网中搜索并保存退出

{
          "registry-mirrors": ["https://8r73devx.mirror.aliyuncs.com"]
}

5.重启docker

 systemctl restart docker

6.查看系统版本信息

[root@localhost ~]# docker version 
client: docker engine - community
 version:           27.2.1
 api version:       1.47
 go version:        go1.22.7
 git commit:        9e34c9b
 built:             fri sep  6 12:09:42 2024
 os/arch:           linux/amd64
 context:           default

server: docker engine - community
 engine:
  version:          27.2.1
  api version:      1.47 (minimum version 1.24)
  go version:       go1.22.7
  git commit:       8b539b8
  built:            fri sep  6 12:07:57 2024
  os/arch:          linux/amd64
  experimental:     false
 containerd:
  version:          1.7.21
  gitcommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  version:          1.1.13
  gitcommit:        v1.1.13-0-g58aa920
 docker-init:
  version:          0.19.0
  gitcommit:        de40ad0

7.运行docker

[root@localhost ~]# 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/

[root@localhost ~]# 

到此这篇关于dockers安装配置镜像加速器的实现的文章就介绍到这了,更多相关dockers安装配置镜像加速器内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网! 

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

docker国内镜像源配置及走代理设置小结

02-14

更改docker默认数据目录的方法步骤

02-14

kubeadm部署k8s集群全过程

02-14

docker目录挂载的新语法小结

02-14

Docker中限制CPU和内存的使用的方法

02-14

Docker集成CI/CD的项目实践

02-14

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论