cdn网站网络加速器,网站 展示板,深汕特别合作区包括哪些地方,中山市做网站本文以 CentOS7.8 为例安装 Docker 26.1.4 、Docker Compose、以及 Docker 镜像仓库。
1.安装Docker社区版
1.1 安装准备
1.1.1 检查系统环境
Docker 不支持32位的 CentOS 7 系统#xff0c;要求系统内核版本为3.10 以上#xff0c;可以通过命令 uname -r 来查看当前系统…本文以 CentOS7.8 为例安装 Docker 26.1.4 、Docker Compose、以及 Docker 镜像仓库。
1.安装Docker社区版
1.1 安装准备
1.1.1 检查系统环境
Docker 不支持32位的 CentOS 7 系统要求系统内核版本为3.10 以上可以通过命令 uname -r 来查看当前系统的内核版本。
[rootDocker ~]# uname -r
3.10.0-1127.el7.x86_64
[rootDocker ~]# 1.1.2卸载旧版本的Docker
如果系统中已经安装了旧版本的Docker建议卸载后再安装新版本。可以使用命令yum remove来卸载旧版本的Docker及其相关组件。
yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-selinux \docker-engine-selinux \docker-engine \docker-ce1.1.3更新yum源
这里更新为阿里云 yum 源更新之前先做备份
[rootDocker ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[rootDocker ~]# 然后下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo[rootDocker ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2024-12-19 09:59:12-- https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 124.236.28.176, 124.236.28.180, 124.238.244.131, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|124.236.28.176|:443... 已连接。
已发出 HTTP 请求正在等待回应... 200 OK
长度2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”100%[] 2,523 --.-K/s 用时 0s 2024-12-19 09:59:17 (115 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])[rootDocker ~]# 最后运行 yum makecache 生成缓存
[rootDocker ~]# yum makecache1.2安装Docker
1.2.1安装依赖包
Docker 的安装需要一些依赖包包括 yum-utils、device-mapper-persistent-data 和 lvm2 等。可以使用命令yum install -y yum-utils device-mapper-persistent-data lvm2来安装这些依赖包。
yum install -y yum-utils \device-mapper-persistent-data \lvm2 --skip-broken1.2.2 配置Docker的yum源
为了安装 Docker需要配置 Docker 的 yum 源。可以使用命令yum-config-manager --add-repo来添加Docker的官方源或国内镜像源如阿里云镜像源。添加后使用命令yum makecache fast来更新 yum 缓存。
[rootDocker ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[rootDocker ~]# 查看内容
[rootDocker ~]# cat /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
nameDocker CE Stable - $basearch
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled1
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-stable-debuginfo]
nameDocker CE Stable - Debuginfo $basearch
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-stable-source]
nameDocker CE Stable - Sources
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-test]
nameDocker CE Test - $basearch
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-test-debuginfo]
nameDocker CE Test - Debuginfo $basearch
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-test-source]
nameDocker CE Test - Sources
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-nightly]
nameDocker CE Nightly - $basearch
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-nightly-debuginfo]
nameDocker CE Nightly - Debuginfo $basearch
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-nightly-source]
nameDocker CE Nightly - Sources
baseurlhttps://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
enabled0
gpgcheck1
gpgkeyhttps://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[rootDocker ~]# 然后更新 yum 缓存
[rootDocker ~]# yum makecache fast1.2.3安装Docker社区版
输入 yum install -y docker-ce 命令开始安装
[rootDocker ~]# yum install -y docker-ce
已加载插件fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
正在解决依赖关系
-- 正在检查事务
--- 软件包 docker-ce.x86_64.3.26.1.4-1.el7 将被 安装
-- 正在处理依赖关系 container-selinux 2:2.74它被软件包 3:docker-ce-26.1.4-1.el7.x86_64 需要
……
已安装:docker-ce.x86_64 3:26.1.4-1.el7 作为依赖被安装:container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.6.33-3.1.el7 docker-buildx-plugin.x86_64 0:0.14.1-1.el7 docker-ce-cli.x86_64 1:26.1.4-1.el7 docker-ce-rootless-extras.x86_64 0:26.1.4-1.el7 docker-compose-plugin.x86_64 0:2.27.1-1.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8 完毕
[rootDocker ~]# 安装过程截图如下 1.3启动Docker
先关闭并禁用防火墙随机启动
[rootDocker ~]# systemctl stop firewalld
[rootDocker ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[rootDocker ~]# 启动之前输入docker images
[rootDocker ~]# docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[rootDocker ~]# 说明 docker 没有启动现在启动并查看状态
[rootDocker ~]# systemctl start docker
[rootDocker ~]# systemctl status docker
● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)Active: active (running) since 四 2024-12-19 10:29:47 CST; 7s agoDocs: https://docs.docker.comMain PID: 26341 (dockerd)Tasks: 10Memory: 35.1MCGroup: /system.slice/docker.service└─26341 /usr/bin/dockerd -H fd:// --containerd/run/containerd/containerd.sock12月 19 10:29:45 Docker systemd[1]: Starting Docker Application Container Engine...
12月 19 10:29:45 Docker dockerd[26341]: time2024-12-19T10:29:45.88836213608:00 levelinfo msgStarting up
12月 19 10:29:46 Docker dockerd[26341]: time2024-12-19T10:29:46.22421987908:00 levelinfo msgLoading containers: start.
12月 19 10:29:46 Docker dockerd[26341]: time2024-12-19T10:29:46.89846996408:00 levelinfo msgLoading containers: done.
12月 19 10:29:47 Docker dockerd[26341]: time2024-12-19T10:29:47.00595524708:00 levelinfo msgDocker daemon commitde5c9cf containerd-snapshotterfalse storage-driveroverlay2 version26.1.4
12月 19 10:29:47 Docker dockerd[26341]: time2024-12-19T10:29:47.00659903508:00 levelinfo msgDaemon has completed initialization
12月 19 10:29:47 Docker dockerd[26341]: time2024-12-19T10:29:47.16917292708:00 levelinfo msgAPI listen on /run/docker.sock
12月 19 10:29:47 Docker systemd[1]: Started Docker Application Container Engine.
[rootDocker ~]# 查看 docker 版本
[rootDocker ~]# docker -v
Docker version 26.1.4, build 5650f9b
[rootDocker ~]# 或者同时可以查看到服务端和客户端信息
[rootDocker ~]# docker version
Client: Docker Engine - CommunityVersion: 26.1.4API version: 1.45Go version: go1.21.11Git commit: 5650f9bBuilt: Wed Jun 5 11:32:04 2024OS/Arch: linux/amd64Context: defaultServer: Docker Engine - CommunityEngine:Version: 26.1.4API version: 1.45 (minimum version 1.24)Go version: go1.21.11Git commit: de5c9cfBuilt: Wed Jun 5 11:31:02 2024OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.6.33GitCommit: d2d58213f83a351ca8f528a95fbd145f5654e957runc:Version: 1.1.12GitCommit: v1.1.12-0-g51d5e94docker-init:Version: 0.19.0GitCommit: de40ad0
[rootDocker ~]# 1.4配置镜像加速
由于 Docker 默认从官方镜像源下载镜像速度可能较慢。可以配置国内镜像源如阿里云镜像源来加速镜像的下载。
编辑 /etc/docker/daemon.json 文件内容如下
[rootDocker ~]# vim /etc/docker/daemon.json
[rootDocker ~]# cat /etc/docker/daemon.json
{registry-mirrors: [https://registry.docker-cn.com,http://hub-mirror.c.163.com,https://docker.mirrors.ustc.edu.cn,https://dockerhub.azk8s.cn,https://mirror.ccs.tencentyun.com,https://registry.cn-hangzhou.aliyuncs.com,https://docker.mirrors.ustc.edu.cn,https://docker.1panel.live,https://atomhub.openatom.cn/,https://hub.uuuadc.top,https://docker.anyhub.us.kg,https://dockerhub.jobcher.com,https://dockerhub.icu,https://docker.ckyl.me,https://docker.awsl9527.cn]
}重载 systemd 服务和重启 docker
[rootDocker ~]# systemctl daemon-reload
[rootDocker ~]# systemctl restart docker
[rootDocker ~]# 2.安装Docker compose
Docker Compose 是一个用于定义和运行多容器应用程序的工具。它是实现流畅、高效开发和部署体验的关键。
Compose 简化了对整个应用程序堆栈的控制使得在单个、易于理解的 YAML 配置文件中管理服务、网络和卷变得轻而易举。然后只需一个命令您就可以从配置文件中创建并启动所有服务。
Compose 适用于所有环境包括生产环境、暂存环境、开发环境、测试环境以及持续集成CI工作流。它还提供了管理应用程序整个生命周期的命令 启动、停止和重建服务 查看运行服务的状态 实时查看运行服务的日志输出 在服务上运行一次性命令
2.1下载docker-compose文件
通过curl命令下载并指定保存到 /usr/local/bin/docker-compose 目录下
curl -L https://github.com/docker/compose/releases/download/v2.32.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose如下
[rootDocker ~]# curl -L https://github.com/docker/compose/releases/download/v2.32.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 61.6M 100 61.6M 0 0 2078k 0 0:00:30 0:00:30 --:--:-- 2153k
[rootDocker ~]# 2.2增加文件执行权限
[rootDocker ~]# chmod x /usr/local/bin/docker-compose
[rootDocker ~]# 查看版本
[rootDocker ~]# docker-compose version
Docker Compose version v2.32.1
[rootDocker ~]# 3.Docker镜像仓库搭建
搭建镜像仓库可以基于Docker官方提供的DockerRegistry来实现。
https://docs.docker.com/registry/3.1搭建简化版的镜像仓库
Docker 官方提供了一个简化版的 Docker Registry 镜像具备完整的仓库管理功能但缺乏图形化界面。下面是一个简单的搭建命令
docker run -d \--restartalways \--name registry \-p 5000:5000 \-v registry-data:/var/lib/registry \registry这个命令中的参数说明 -d: 后台运行容器。 --restartalways: 设置容器总是在 Docker 启动时重新启动。 --name registry: 为容器指定一个名字这里是 registry。 -p 5000:5000: 将主机的 5000 端口映射到容器的 5000 端口。 -v registry-data:/var/lib/registry: 挂载数据卷 registry-data 到容器内的 /var/lib/registry 目录用于持久化存储镜像数据。 registry: 使用的镜像名称。 通过上述命令就成功运行了一个 Docker Registry 服务。访问
http://192.168.250.22:5000/v2/_catalog可以查看当前私有镜像服务中包含的镜像 暂为空。
3.2搭建带有图形化界面的镜像仓库
通过 Docker Compose可以很容易地搭建一个带有图形化界面的 Docker Registry 服务。
以下是一个简单的 docker-compose.yml 文件
version: 3.0
services:registry:image: registryvolumes:- ./registry-data:/var/lib/registryui:image: joxit/docker-registry-ui:staticports:- 8080:80environment:- REGISTRY_TITLE我的私有仓库- REGISTRY_URLhttp://registry:5000depends_on:- registry3.3 配置 Docker 信任地址
这里采用的是 http 协议默认不被 Docker 信任所以需要做一个配置
编辑 /etc/docker/daemon.json文件
[rootDocker ~]# vim /etc/docker/daemon.json
[rootDocker ~]# 然后添加 insecure-registries: [http://192.168.250.22:8080] [rootDocker ~]# cat /etc/docker/daemon.json
{registry-mirrors: [https://registry.docker-cn.com,http://hub-mirror.c.163.com,https://docker.mirrors.ustc.edu.cn,https://dockerhub.azk8s.cn,https://mirror.ccs.tencentyun.com,https://registry.cn-hangzhou.aliyuncs.com,https://docker.mirrors.ustc.edu.cn,https://docker.1panel.live,https://atomhub.openatom.cn/,https://hub.uuuadc.top,https://docker.anyhub.us.kg,https://dockerhub.jobcher.com,https://dockerhub.icu,https://docker.ckyl.me,https://docker.awsl9527.cn],insecure-registries: [http://192.168.250.22:8080]
}然后重载 Docker 守护进程配置并重启 Docker
[rootDocker ~]# systemctl daemon-reload
[rootDocker ~]# systemctl restart docker这样就成功搭建了一个简化版的 Docker 镜像仓库并且还可以使用 Docker Compose 部署一个带有图形化界面的 Docker Registry。
然后运行命令docker-compose up -d
[rootDocker ~]# docker-compose up -d
WARN[0000] /root/docker-compose.yml: the attribute version is obsolete, it will be ignored, please remove it to avoid potential confusion
[] Running 12/12✔ ui Pulled 50.9s ✔ 540db60ca938 Pull complete 15.1s ✔ 197dc8475a23 Pull complete 16.7s ✔ 39ea657007e5 Pull complete 16.9s ✔ 37afbf7d4c3d Pull complete 17.0s ✔ 0c01f42c3df7 Pull complete 17.3s ✔ d590d87c9181 Pull complete 17.4s ✔ 3333c94ae44f Pull complete 17.6s ✔ 33d7cca6fc9f Pull complete 17.9s ✔ 076b2dd9bdd1 Pull complete 18.0s ✔ b70198f04ee7 Pull complete 18.2s ✔ 1fb6c5acc953 Pull complete 18.3s
[] Running 3/3✔ Network root_default Created 0.2s ✔ Container root-registry-1 Started 1.6s ✔ Container root-ui-1 Started 2.0s
[rootDocker ~]# 然后输入仓库地址
http://192.168.250.22:8080/就可以看到私有镜像查看的 UI 界面如下