1 Overview:
1.1 Environment
The version information is as follows:
a. Operating system: centos 7.6, amd64
b, server docker version: v18.06.0
c, server git version: 1.8.3.1
d, target compiled docker version: v18.09.2
2 Preparation
2.1 Install docker on the host
The compilation environment is a container, so you need to install the container engine on the host, and run a container in the subsequent steps to compile the target software docker-ce v18.09.2.
yum install yum-utils -y
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates
yum install -y docker-ce-18.06.0.ce-3.el7
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://bxsfpjcb.mirror.aliyuncs.com", "https://registry.docker-cn.com"],
"max-concurrent-downloads": 10,
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-size": "100m",
"max-file": "3"
},
"live-restore": true,
"exec-opts": ["native.cgroupdriver=systemd"],
"graph": "/var/lib/docker"
}
EOF
systemctl daemon-reload
systemctl enable docker
systemctl restart docker
2.2 Build the build environment image
Take the Dockerfile in the docker-ce/components/engine directory to Alibaba Cloud Mirror Service to build, and the resulting image is:
registry.cn-shenzhen.aliyuncs.com/gzlj/docker-build:v18.09.2
3 Compilation process:
3.1 Download docker-ce source code
mkdir -p /opt
cd /opt
git clone -b v18.09.2 https://gitee.com/zjuhunter/docker-ce.git
cd docker-ce/components/engine
3.2 Start the compilation environment container and execute the compilation script
Currently located in the /opt/docker-ce/components/engine directory of the host, start the container of the compilation environment, mount the source directory into the container, execute the hack/make.sh script in docker-ce, and wait a few minutes. Compilation is completed, and finally a bunch of binary files appear in the bundles/binary-daemon/ directory under the source code directory.
docker run \
--rm \
-it \
--privileged \
-v $PWD:/go/src/github.com/docker/docker \
registry.cn-shenzhen.aliyuncs.com/gzlj/docker-build:v18.09.2 \
bash
# 现在已进入容器内部,执行编译脚本
export DOCKER_GITCOMMIT=v18.09.2
hack/make.sh binary
4 Summary:
The docker-ce project does not use go modules to manage dependencies. After entering the compilation environment, there is no need to execute any dependencies-related instructions (such as go get, etc.). If the docker-ce project is forced to become a go module project, dependency-related errors and undefined field errors in the code will occur when the compilation script is executed.