cd /usr/local/docker/src/github.com
git clone https://github.com/krallin/tini.git
下载docker-runc相关代码
mkdir -p /usr/local/docker/src/github.com/opencontainers
cd /usr/local/docker/src/github.com/opencontainers
git clone https://github.com/opencontainers/runc.git
下载docker-containerd...相关代码
mkdir -p /usr/local/docker/src/github.com/containerd
cd /usr/local/docker/src/github.com/containerd
git clone https://github.com/containerd/containerd.git
三、编译二制文件
切换docker-ce至18.09版本
cd /usr/local/docker/src/github.com/docker/docker-ce
git checkout 18.09
Branch 18.09 set up to track remote branch 18.09 from origin.
Switched to a new branch '18.09'
根据docker-ce/components/engine/hack/dockerfile/install/runc.installer切换至对应commit id(RUNC_COMMIT=96ec2177ae841256168fcf76954f7177af9446eb)
cd /usr/local/docker/src/github.com/opencontainers/runc
[root@localhost runc]# git checkout -q 96ec2177ae841256168fcf76954f7177af9446eb
#If using RHEL7 kernels (3.10.0 el7), disable kmem accounting/limiting
[root@localhost runc]# make BUILDTAGS="seccomp apparmor selinux nokmem" static
[root@localhost runc]# ldd runc
not a dynamic executable
3)编译containerd
据编译命令编译
docker-ce/components/engine/hack/dockerfile/install/containerd.installer
CONTAINERD_COMMIT=9754871865f7fe2f4e74d43e2fc7ccd237edcbce # v1.2.2
cd /usr/local/docker/src/github.com/containerd/containerd/
[root@localhost containerd]# git checkout -q 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
[root@localhost containerd]# make EXTRA_FLAGS="-buildmode pie" EXTRA_LDFLAGS='-extldflags "-fno-PIC -static"' BUILDTAGS="netgo osusergo static_build"
[root@localhost containerd]# ldd bin/ctr
not a dynamic executable
[root@localhost containerd]# ldd bin/containerd*
bin/containerd:
not a dynamic executable
bin/containerd-shim:
not a dynamic executable
bin/containerd-shim-runc-v1:
not a dynamic executable
bin/containerd-stress:
not a dynamic executable
4)编译docker-init
cd /usr/local/docker/src/github.com/tini
[root@localhost tini]# git checkout -q fec3683b971d9c3ef73f284f176672c44b44866
[root@localhost tini]# cmake .
[root@localhost tini]# make tini-static
[root@localhost tini]# ldd tini-static
not a dynamic executable
[root@localhost tini]# cp tini-static docker-init
5)编译docker-proxy
cd /usr/local/docker/src/github.com/docker/libnetwork
[root@localhost libnetwork]# git checkout -q 2cfbf9b1f98162a55829a21cc603c76072a75382
[root@localhost libnetwork]# CGO_ENABLED=0 go build -o docker-proxy github.com/docker/libnetwork/cmd/proxy
[root@localhost libnetwork]# ldd docker-proxy
not a dynamic executable
6)编译docker dockerd
cd /usr/local/docker/src/github.com/docker/cli
[root@localhost cli]#export VERSION=18.09
[root@localhost cli]#export GITCOMMIT=4c52b90
[root@localhost cli]# make binary
WARNING: you are not in a container.
Use "make -f docker.Makefile binary" or set
DISABLE_WARN_OUTSIDE_CONTAINER=1 to disable this warning.
Press Ctrl+C now to abort.
WARNING: binary creates a Linux executable. Use cross for macOS or Windows.
./scripts/build/binary
Building statically linked build/docker-linux-amd64
[root@localhost cli]# ldd build/docker
not a dynamic executable
[root@localhost cli]# build/docker -v
Docker version 18.09, build 4c52b90
cd /usr/local/docker/src/github.com/docker/docker
[root@localhost docker]# hack/make.sh binary
#WARNING! I don't seem to be running in a Docker container.
#The result of this command might be an incorrect build, and will not be
#officially supported.
#Try this instead: make all
Removing bundles/
---> Making bundle: binary (in bundles/binary)
Building: bundles/binary-daemon/dockerd-18.09
github.com/docker/docker/cmd/dockerd
/tmp/go-link-867197439/000008.o: In function mygetgrouplist':/usr/local/go1.10.6/go/src/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking/tmp/go-link-867197439/000007.o: In functionmygetgrgid_r':
/usr/local/go1.10.6/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-867197439/000007.o: In function mygetgrnam_r':/usr/local/go1.10.6/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking/tmp/go-link-867197439/000007.o: In functionmygetpwnam_r':
/usr/local/go1.10.6/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-867197439/000007.o: In function `mygetpwuid_r':
/usr/local/go1.10.6/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Created binary: bundles/binary-daemon/dockerd-18.09
[root@localhost docker]# bundles/binary-daemon/dockerd -v
Docker version 18.09, build 4c52b90/18.09
[root@localhost docker]# ldd bundles/binary-daemon/dockerd
not a dynamic executable
拷贝编译完成的docker相关二制文件
[root@localhost ~]# mkdir /tmp/18.09-docker
[root@localhost ~]#cd /usr/local/docker/src/github.com
[root@localhost github.com]# cp docker/libnetwork/docker-proxy /tmp/18.09-docker/
[root@localhost github.com]# cp docker/cli/build/docker /tmp/18.09-docker/
[root@localhost github.com]# cp docker/docker/bundles/binary-daemon/dockerd /tmp/18.09-docker/
[root@localhost github.com]# cp containerd/containerd/bin/ctr containerd/containerd/bin/containerd containerd/containerd/bin/containerd-shim /tmp/18.09-docker/
[root@localhost github.com]# cp tini/docker-init /tmp/18.09-docker/
[root@localhost github.com]# cp opencontainers/runc/runc /tmp/18.09-docker/
[root@localhost github.com]# ls -lrt /tmp/18.09-docker/
total 160688
-rwxr-xr-x. 1 root root 2841376 Jan 25 01:38 docker-proxy
-rwxr-xr-x. 1 root root 50711753 Jan 25 01:38 docker
-rwxr-xr-x. 1 root root 53918880 Jan 25 01:39 dockerd
-rwxr-xr-x. 1 root root 28075792 Jan 25 01:40 containerd
-rwxr-xr-x. 1 root root 4968800 Jan 25 01:40 containerd-shim
-rwxr-xr-x. 1 root root 15816304 Jan 25 01:40 ctr
-rwxr-xr-x. 1 root root 845080 Jan 25 01:41 docker-init
-rwxr-xr-x. 1 root root 7352008 Jan 25 01:42 runc
[root@localhost ~]# docker version
Client:
Version: 18.09
API version: 1.39
Go version: go1.10.6
Git commit: 4c52b90
Built: Fri Jan 25 10:31:01 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 4c52b90/18.09
Built: Fri Jan 25 10:33:42 2019
OS/Arch: linux/amd64
Experimental: false