编译docker的必要条件
这阵子在公司搞docker container这些技术,docker编译网上查了一下木有靠谱的。只好自己动手丰衣足食了。
声明:你编译docker不需要git pull它的源码,必备条件只有一个,就是你有一台能pull镜像的docker主机就行了。
本人环境是VMware下CentOS Linux release 7.1.1503 (Core) [x86_64]
以下为编译过程的具体记录
1.pull docker-dev:1.8.2的镜像
[root@myserv docker]# docker pull docker-dev:1.8.2
Pulling repository docker-dev
ab03141ac2e9: Pulling dependent layers
d3a1f33e8a5a: Download complete
c22013c84729: Download complete
d74508fb6632: Download complete
91e54dfb1179: Download complete
758970a22420: Download complete
62fd5b9e4d35: Download complete
944fcdea21b1: Download complete
ab975b7812f0: Download complete
0f860819eb9c: Download complete
adcf22790962: Download complete
c79325ee5872: Download complete
115d2806e84a: Download complete
1705282a2f45: Download complete
5d8bf41b5802: Download complete
3388f79cde5c: Download complete
979009c412cd: Download complete
11eaa2b57f9e: Download complete
b3ff0a3e16f1: Download complete
a7cc3d81aeed: Download complete
94b8248ce242: Download complete
006aa3cb8d92: Download complete
5ce85bb004d1: Download complete
28907ad32b10: Download complete
919096bcd935: Download complete
2a138d63ee40: Download complete
2b2733893e80: Download complete
ab03141ac2e9: Download complete
906727032fc8: Download complete
c296523a5eea: Download complete
f38d4f3bc631: Download complete
b5564cf04aab: Download complete
cd3a9bdbad49: Download complete
a223a267d4b0: Download complete
0912427504fa: Download complete
9d153769f49b: Download complete
4ec1b8c4c270: Download complete
7ca719ee5f14: Download complete
3b994c4a49de: Download complete
062d730e6007: Download complete
ac1892714a82: Download complete
ac43d240b0a2: Download complete
dbab3fbdd774: Download complete
79d657b6d894: Download complete
725fa96f33ab: Download complete
ad50f4526814: Download complete
ee0aa2630de6: Download complete
a9314782dbbf: Download complete
23f7502170cd: Download complete
8bfc29dd7728: Download complete
Status: Downloaded newer image for docker-dev:1.8.2
2.创建一个目录存放docker编译后生成的文件夹
[root@myserv home]# mkdir -p /home/dockerbuild/bundles
[root@myserv home]# cd /home/dockerbuild/
3.运行刚刚pull好的docker-dev镜像,然后在容器里进行docker的编译工作
[root@myserv home]# docker run --rm -it --privileged \
-e BUILDFLAGS -e DOCKER_CLIENTONLY -e DOCKER_EXECDRIVER -e DOCKER_EXPERIMENTAL \
-e DOCKER_GRAPHDRIVER -e DOCKER_STORAGE_OPTS -e DOCKER_USERLANDPROXY -e TESTDIRS -e TESTFLAGS -e TIMEOUT \
-v /home/dockerbuild/bundles:/go/src/github.com/docker/docker/bundles docker-dev:1.8.2 bash root@87193e358c88:/go/src/github.com/docker/docker# hack/make.sh binary ---> Making bundle: binary (in bundles/1.8.2/binary)
Building: bundles/1.8.2/binary/docker-1.8.2
Created binary: bundles/1.8.2/binary/docker-1.8.2
4.查看编译输出并验证编译结果
root@87193e358c88:/go/src/github.com/docker/docker# ls -l bundles/1.8.2/binary/
total 21104
lrwxrwxrwx 1 root root 12 Sep 15 10:20 docker -> docker-1.8.2
-rwxr-xr-x 1 root root 21599668 Sep 15 10:20 docker-1.8.2
-rw-r--r-- 1 root root 47 Sep 15 10:20 docker-1.8.2.md5
-rw-r--r-- 1 root root 79 Sep 15 10:20 docker-1.8.2.sha256
上述可以看到在容器内,bundles目录已经有了编译好的docker程序文件了。退出容器后,在本机/home/dockerbuild/bundles/1.8.2/binary目录下会得到一个编译完毕的docker。
[root@myserv dockerbuild]# cd bundles/
[root@myserv bundles]# ls
1.8.2 latest
[root@myserv bundles]# cd 1.8.2/
[root@myserv 1.8.2]# ls
binary
[root@myserv binary]# ls -l
total 21104
lrwxrwxrwx 1 root root 12 Sep 15 18:20 docker -> docker-1.8.2
-rwxr-xr-x 1 root root 21599668 Sep 15 18:20 docker-1.8.2
-rw-r--r-- 1 root root 47 Sep 15 18:20 docker-1.8.2.md5
-rw-r--r-- 1 root root 79 Sep 15 18:20 docker-1.8.2.sha256
[root@myserv binary]# ./docker version
Client:
Version: 1.8.2
API version: 1.20
Go version: go1.4.2
Git commit: 0a8c2e3
Built: Tue Sep 15 10:20:40 UTC 2015
OS/Arch: linux/amd64
Error response from daemon: client and server don't have same version (client API version: 1.20, server API version: 1.19)
题外话
官方之所以选择在容器内编译docker的方式是因为容器内部已经集成好编译docker所需的环境及组件了,我也懒得在centos里将依赖一个个装了。
Update 1
容器内的源码目录:/go/src/github.com/docker/docker
其对应的GOPATH设置如下:
root@bd341b3fe6b9:/go/src/github.com/docker/docker# go env GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go:/go/src/github.com/docker/docker/vendor"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
本文到此结束,谢谢。