官方建議docker源碼編譯在docker容器內進行,由於官方提供的容器內已經繼承了編譯須要的環境,若是非要本身搭建編譯環境也不是不能夠,就是稍微有些繁瑣。如下以1.8.2版本爲例。linux
docker pull docker-dev:版本
具體版本能夠查看官網。
ps:該鏡像較大,能夠考慮從國內鏡像下載。git
[root@myserv home]# mkdir -p /home/dockerbuild/bundles [root@myserv home]# cd /home/dockerbuild/
[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
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。 github
[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)