准备
首先,下载第三版的源码包
再下载两个libbsd库
http://elrepo.reloumirrors.net/testing/el6/x86_64/RPMS/libbsd-0.2.0-4.el6.elrepo.x86_64.rpm
http://elrepo.reloumirrors.net/testing/el6/x86_64/RPMS/libbsd-devel-0.2.0-4.el6.elrepo.x86_64.rpm
镜像build
1. 解压src.3e.tar.gz
1 $ tar -zxvf src.3e.tar.gz
2. Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 FROM centos:latest
MAINTAINER shareinto
COPY libbsd-0.2.0-4.el6.elrepo.x86_64.rpm /tmp/libbsd-0.2.0-4.el6.elrepo.x86_64.rpm
COPY libbsd-devel-0.2.0-4.el6.elrepo.x86_64.rpm /tmp/libbsd-devel-0.2.0-4.el6.elrepo.x86_64.rpm
RUN yum install make -y \
&& yum install gcc -y \
&& rpm -ivh /tmp/libbsd-0.2.0-4.el6.elrepo.x86_64.rpm \
&& rpm -ivh /tmp/libbsd-devel-0.2.0-4.el6.elrepo.x86_64.rpm \
&& rm -rf /tmp/libbsd-0.2.0-4.el6.elrepo.x86_64.rpm \
&& rm -rf /tmp/libbsd-devel-0.2.0-4.el6.elrepo.x86_64.rpm
COPY apue.3e /root/apue.3e
WORKDIR /root/apue.3e
RUN make \
&& cp ./include/apue.h ./lib/error.c /usr/include \
&& cp ./lib/libapue.a /usr/lib \
&& rm -rf /root/apue.3e
WORKDIR /root
3. build
1 $ docker build -t apue .
4. alias一下编译命令 方便编译
1 $ vi ~/.bashrc添加下面到.bashrc里面
1 alias apue='apue(){ docker run --rm -v $(pwd):/root apue gcc $1 -o $(echo $1 | sed "s/\.c//") -lapue; };apue'
1 $ source ~/.bashrc
5. 编译
1 $ apue ls.c将会自动生成可执行文件ls