小知识:详解Docker源码编译安装

最近在尝试阅读docker源码,一直想弄明白docker关于namespace等的代码的在哪,以及怎么触发。然而在阅读时发现根本找不到代码。。。想着还是先源码安装下docker,然后边运行边打印些调试信息看看再说

安装之前

docker源码需在docker容器编译环境中编译,所以先安装docker,安装环境依旧是ubuntu14.04

?
1
2
3
4
5
echo “deb https://apt.dockerproject.org/repo ubuntu-trusty main” | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118e89f3a912897c070adbf76221572c52609d
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install docker-engine

起初是使用apt-get install docker.io安装,但在编译源码的时候会遇到arg错误。

安装

docker的安装命令很简单,虽然错误很多= =

?
1
2
3
4
5
apt-get install make git golang
git clone https://git@github.com/docker/docker
cd docker
make build
make binary

遇到的问题与解决方案

unknown instruction: arg

原因:

docker hubs automated build is still running docker 1.8 and doesnt support arg yet. there is a github issue tracking their upgrade to 1.9.

解决方案:采用安装最新的docker-engine方式

docker daemon启动失败

复制代码 代码如下:
fata[0000] error starting daemon: error initializing graphdriver: “/var/lib/docker” contains several valid graphdrivers: aufs, devicemapper; please cleanup or explicitly choose storage driver (-s <driver>)

解决方案:移除devicemap文件夹,如 mv /var/lib/docker/devicemapper/ .

make build出错一

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
step 6 : run apt-get update && apt-get install -y apparmor apt-utils aufs-tools automake bash-completion binutils-mingw-w64 bsdmainutils btrfs-tools build-essential clang createrepo curl dpkg-sig gcc-mingw-w64 git iptables jq libapparmor-dev libcap-dev libltdl-dev libsqlite3-dev libsystemd-journal-dev libtool mercurial net-tools pkg-config python-dev python-mock python-pip python-websocket ubuntu-zfs xfsprogs libzfs-dev tar zip –no-install-recommends && pip install awscli==1.10.15
—> running in 32ad02db3575
get:1 http://ppa.launchpad.net trusty inrelease [15.5 kb]
ign http://httpredir.debian.org jessie inrelease
get:2 http://httpredir.debian.org jessie-updates inrelease [142 kb]
get:3 http://security.debian.org jessie/updates inrelease [63.1 kb]
get:4 http://httpredir.debian.org jessie release.gpg [2373 b]
get:5 http://ppa.launchpad.net trusty/main amd64 packages [5150 b]
get:6 http://httpredir.debian.org jessie-updates/main amd64 packages [17.6 kb]
get:7 http://httpredir.debian.org jessie release [148 kb]
get:8 http://httpredir.debian.org jessie/main amd64 packages [9035 kb]
get:9 http://security.debian.org jessie/updates/main amd64 packages [232 kb]
fetched 9662 kb in 19s (504 kb/s)
w: failed to fetch http://httpredir.debian.org/debian/dists/jessie/main/binary-amd64/packages hash sum mismatch
w: failed to fetch http://security.debian.org/dists/jessie/updates/main/binary-amd64/packages hash sum mismatch
e: some index files failed to download. thew: failed to fetch http://httpredir.debian.org/debian/dists/jessie/main/binary-amd64/packages hash sum mismatch

看样子是源的问题哎╮(╯▽╰)╭

而且是run指令,应该是dockerfile运行容器之后的源错误,so,看下docker/dockerfile

?
1
2
# arg apt_mirror=httpredir.debian.org
run sed -i s/httpredir.debian.org/$apt_mirror/g /etc/apt/sources.list

在这里修改了源~从网上重新找个ftp.cn.debian.org,然而,。。。还是错。。。

好吧,那把这两句直接全部注释掉,用163的debian源内容echo到容器里,执行

复制代码 代码如下:
run echo “deb jessie main non-free contrib\ndeb jessie-updates main non-free contrib\ndeb jessie-backports main non-free contrib\ndeb-src jessie main non-free contrib\ndeb-src jessie-updates main non-free contrib\ndeb-src jessie-backports main non-free contrib\ndeb jessie/updates main non-free contrib\ndeb-src jessie/updates main non-free contrib” | tee /etc/apt/sources.list

再执行make build,出现依赖问题,那就用aptitude吧

?
1
2
run apt-get update && apt-get install -y aptitude
run aptitude install -y \

(同时去掉–no-install-recommends\那一行)

make build出错二

?
1
2
3
4
5
6
7
8
9
10
11
12
step 15 : run set -x   && export seccomp_path=”$(mktemp -d)”   && curl -fssl “https://github.com/seccomp/libseccomp/releases/download/v${seccomp_version}/libseccomp-${seccomp_version}.tar.gz”     | tar -xzc “$seccomp_path” –strip-components=1   && (     cd “$seccomp_path”     && ./configure –prefix=/usr/local     && make     && make install && ldconfig   )   && rm -rf “$seccomp_path”
—> running in 4ad66d28289d
+ mktemp -d
+ export seccomp_path=/tmp/tmp.twpyfcirjc
+ curl -fssl https://github.com/seccomp/libseccomp/releases/download/v2.3.1/libseccomp-2.3.1.tar.gz
+ tar -xzc /tmp/tmp.twpyfcirjc –strip-components=1
curl: (56) ssl read: error:00000000:lib(0):func(0):reason(0), errno 104
gzip: stdin: unexpected end of file
tar: unexpected eof in archive
tar: unexpected eof in archive
tar: error is not recoverable: exiting now

网络问题,网上有说先下载下来再用add添加进去,结果发现校园网貌似访问这挺快的,连上vpn再执行就行了。。

make binary 出错

复制代码 代码如下:
error:/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: fork/exec /usr/bin/gcc: cannot allocate memory

内存不足~增大虚拟机内存呗

安装结果

make build

%小知识:详解Docker源码编译安装-猿站网-插图

make binary

%小知识:详解Docker源码编译安装-1猿站网-插图

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/lwyeluo/article/details/51765309

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:详解从 0 开始使用 Docker 快速搭建 Hadoop 集群环境

2023-4-18 12:26:38

建站知识

小知识:详解使用Docker容器来源码编译etcd

2023-4-18 12:36:34

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索