如何编译在Docker中使用内核函数的C代码并在容器中使用pci设备?
我有一个Makefile使用PCI设备的一些C ++代码
all: g++ -o executable main.cpp dragon.pb.cc -std=c++11 -O3 -I/usr/include/postgresql -I/usr/include/hiredis -lzmq -lprotobuf -lpthread -lpq -lhiredis clean: rm executable
它依赖于这个使用内核函数的C库。 这个libraby的Makefile是
# dist and build are folders, not phony targets .PHONY: all package clean all: dragon.pb.cc dragon_pb2.py package dragon.pb.cc: dragon.proto protoc --cpp_out=. dragon.proto dragon_pb2.py: dragon.proto protoc --python_out=. dragon.proto package: build clean: rm -f dragon.pb.* rm -f dragon_pb* rm -rf build rm -rf dist rm -f MANIFEST
这里是我的Dockerfile
FROM ubuntu:14.04 ENV PG_MAJOR 9.3 RUN apt-get update RUN apt-get install -y git make protobuf-compiler libhiredis-dev postgresql-server-dev-${PG_MAJOR} RUN apt-get install -y g++ RUN apt-get install -y libzmq-dev RUN apt-get install -y libprotobuf-dev RUN apt-get install -y linux-headers-$(uname -r) ADD deployment_key /root/.ssh/id_rsa RUN chmod 600 /root/.ssh/id_rsa RUN echo "StrictHostKeyChecking no" >> /root/.ssh/config RUN echo >> /root/.ssh/config RUN echo "Host bitbucket.org" >> /root/.ssh/config RUN mkdir -p /usr/src/app/ WORKDIR /usr/src/app/ RUN git clone git@bitbucket.org:opticsdevelopment/dragon-protocols.git WORKDIR ./dragon-protocols RUN make dragon.pb.cc RUN cp ./dragon.pb.* ../ COPY . /usr/src/app WORKDIR ../ RUN git clone git@bitbucket.org:opticsdevelopment/dragon-module.git WORKDIR ./dragon-module RUN make all WORKDIR ../ RUN make EXPOSE 5570 CMD ["dragon"]
现在的问题是安装linux-headers。 不知何故,它无法find标题
E: Unable to locate package linux-headers-3.13.0-19-generic E: Couldn't find any package by regex 'linux-headers-3.13.0-19-generic'
如果你的应用程序可以编译任何通用的Linux头
在您的Dockerfile更改
运行apt-get install -y linux-headers – $(uname -r)
只是
运行apt-get install -y linux-headers-generic
或者如果你需要与你的主机系统相同的特定的一个为什么你不只是容量链接这个目录从主机到docker容器与-v?
在你的主机系统上:
sudo apt-get install linux-headers-$(uname -r)
现在你在这里有内核头文件:/ usr / src / linux-headers – $(uname -r)/ include
现在在您的docker运行命令,链接该卷像
-v /usr/src/linux-headers-$(uname -r)/include:/usr/src/linux-headers-$(uname -r)/include