腾讯云服务器centos-7.6编译docker-ce最新版本源码生成rpm包
1. git工具安装及源码下载和配置
1.1 安装git工具
[root@VM_0_10_centos ~]# yum install git
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package git-1.8.3.1-22.el7_8.x86_64 already installed and latest version
1.2 从github下载19.03版本docker-ce源码
[root@VM_0_10_centos home]# git clone -b 19.03 https://github.com/docker/docker-ce.git
Cloning into 'docker-ce'...
remote: Enumerating objects: 1328, done.
remote: Counting objects: 100% (1328/1328), done.
remote: Compressing objects: 100% (843/843), done.
^Zceiving objects: 0% (1345/425634), 444.01 KiB | 7.00 KiB/s
1.3 从github下载docker-ce版本确认
[root@VM_0_10_centos docker-ce]# pwd
/home/docker-ce
[root@VM_0_10_centos docker-ce]# git branch
* 19.03
[root@VM_0_10_centos docker-ce]# cat VERSION
19.03.9
2 修改部分配置加速下载过程
2.1 替换如下目录各文件中github源地址为gitee地址
[root@VM_0_10_centos install]# ls
containerd.installer gometalinter.installer install.sh rootlesskit.installer tini.installer vndr.installer
dockercli.installer gotestsum.installer proxy.installer runc.installer tomlv.installer
[root@VM_0_10_centos install]# pwd
/home/docker-ce/components/engine/hack/dockerfile/install
[root@VM_0_10_centos plugins]# ls
app.installer buildx.installer
[root@VM_0_10_centos plugins]# pwd
/home/docker-ce/components/packaging/plugins
2.1.1 示例proxy.installer
[root@VM_0_10_centos install]# grep "git clone" proxy.installer
#git clone https://github.com/docker/libnetwork.git "$GOPATH/src/github.com/docker/libnetwork"
git clone https://gitee.com/watson2018/docker-libnetwork.git "$GOPATH/src/github.com/docker/libnetwork"
2.1.2 如何找到替换新地址
注册并登陆:https://gitee.com
点击右上角“+”->“新建仓库”
下拉到最下面选择“导入已有仓库”,在输入框中输入https://github.com/docker/libnetwork.git然后确认,一般会提示“检测到目前导入仓库在码云上已有公开同步仓库,点击链接马上访问:”
拷贝相应链接即可使用
3 修改Makefile文件只生成centos-7 rpm安装包
[root@VM_0_10_centos rpm]# pwd
/home/docker-ce/components/packaging/rpm
[root@VM_0_10_centos rpm]# vim Makefile
将第44行centos-8屏蔽
CENTOS_RELEASES := centos-7# centos-8
RHEL_RELEASES := rhel-7
DISTROS := $(FEDORA_RELEASES) $(CENTOS_RELEASES) $(RHEL_RELEASES)
.PHONY: help
help: ## show make targets
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: clean
clean: ## remove build artifacts
[ ! -d rpmbuild ] || $(CHOWN) -R $(shell id -u):$(shell id -g) rpmbuild
$(RM) -r rpmbuild/
.PHONY: rpm
rpm: centos fedora## build all rpm packages
.PHONY: fedora
fedora: $(FEDORA_RELEASES) ## build all fedora rpm packages
.PHONY: centos-8
centos-8: RPMBUILD_EXTRA_FLAGS=--define '_without_btrfs 1'
.PHONY: centos
centos: $(CENTOS_RELEASES) ## build all centos rpm packages
4 编译
4.1 编译命令
[root@VM_0_10_centos docker-ce]# pwd
/home/docker-ce
[root@VM_0_10_centos docker-ce]# make VERSION=19.03.9 CLI_DIR=/home/docker-ce/components/cli/ ENGINE_DIR=/home/docker-ce/components/engine/ -C /home/docker-ce/components/packaging/rpm/ centos
4.2 结果确认
[root@VM_0_10_centos x86_64]# pwd
/home/docker-ce/components/packaging/rpm/rpmbuild/RPMS/x86_64
[root@VM_0_10_centos x86_64]# ll
total 63792
-rw-r--r-- 1 root root 25276016 May 17 11:48 docker-ce-19.03.9-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 40046588 May 17 11:54 docker-ce-cli-19.03.9-3.el7.x86_64.rpm
[root@VM_0_10_centos x86_64]# yum install docker-ce-19.03.9-3.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining docker-ce-19.03.9-3.el7.x86_64.rpm: 3:docker-ce-19.03.9-3.el7.x86_64
Marking docker-ce-19.03.9-3.el7.x86_64.rpm as an update to 3:docker-ce-19.03.8-3.el7.x86_64
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:19.03.8-3.el7 will be updated
---> Package docker-ce.x86_64 3:19.03.9-3.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Updating:
docker-ce x86_64 3:19.03.9-3.el7 /docker-ce-19.03.9-3.el7.x86_64 102 M
Transaction Summary
======================================================================================================================================
Upgrade 1 Package
Total size: 102 M
Is this ok [y/d/N]:
结束