Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile C code that is using kernel function in docker and use pci device in container?

I have a Makefile some C++ code that is using PCI device

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

And It have dependencies on this C library that is using kernel functions. Makefile for this libraby is

    # 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

And here is my 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 [email protected]:opticsdevelopment/dragon-protocols.git
WORKDIR ./dragon-protocols
RUN make dragon.pb.cc
RUN cp ./dragon.pb.* ../
COPY . /usr/src/app
WORKDIR ../
RUN git clone [email protected]:opticsdevelopment/dragon-module.git
WORKDIR ./dragon-module
RUN make all
WORKDIR ../
RUN make
EXPOSE 5570
CMD ["dragon"]

The problem right now is in installing linux-headers. Somehow it can't find headers

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'
like image 782
user1685095 Avatar asked Jul 20 '15 15:07

user1685095


People also ask

Do Docker containers have kernels?

No. Docker image/container only has the application layer of the OS and uses the kernel and CPU of the host machine. That's why docker container boot's so fast. In your host machine kernel is already running, so if you boot your docker container it will share the running kernel and start the container so fast.

Do containers use the host kernel?

The difference between a container and a full-fledged VM is that all containers share the same kernel of the host system. This gives them the advantage of being very fast with almost 0 performance overhead compared with VMs. They also utilize the different computing resources better because of the shared kernel.

Do containers use the same kernel?

Containers share the same operating system kernel and isolate the application processes from the rest of the system.

What is used by the kernel to isolate resources when running Docker containers?

Namespaces. Docker makes use of kernel namespaces to provide the isolated workspace called the container . When you run a container, Docker creates a set of namespaces for that container. These namespaces provide a layer of isolation.


1 Answers

If your app can compile with any generic linux headers

In your Dockerfile change

RUN apt-get install -y linux-headers-$(uname -r)

to just

RUN apt-get install -y linux-headers-generic 

or if you need the same specific one as your host system why dont you just volume link this directory from host to the docker container with the -v?

on your host system:

sudo apt-get install linux-headers-$(uname -r)

Now you have the kernel headers here: /usr/src/linux-headers-$(uname -r)/include

now on your docker container run command, link that volume like

-v /usr/src/linux-headers-$(uname -r)/include:/usr/src/linux-headers-$(uname -r)/include
like image 192
paimpozhil Avatar answered Oct 22 '22 13:10

paimpozhil