Skip to content

Commit a36ab7e

Browse files
committed
BPF : Add dockerfile for image build
1 parent 3d8b3d2 commit a36ab7e

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

x86/bpf/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM x86/ubuntu:2204
2+
3+
WORKDIR /code
4+
5+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
6+
apt-get -y --no-install-recommends install libncurses-dev gawk flex \
7+
bison openssl libssl-dev dkms \
8+
libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm libcap2-dev \
9+
rsync bc pahole git clang binutils-dev dpkg-dev

x86/bpf/README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# BPF samples
22

3-
## Using Ubuntu 22.04 or docker as example
3+
## Using Ubuntu 22.04 as compilation setup
44

55
[Ubuntu get source code](https://wiki.ubuntu.com/Kernel/SourceCode)
66
[Ubuntu Build Your Own Kernel](https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel)
77

88
安装必要的软件依赖
99

1010
apt install -y dpkg-dev
11-
1211
apt-get build-dep linux linux-image-$(uname -r)
1312

14-
在Docker中可以通过指定具体的版本来安装内核代码
13+
在Docker中可以通过指定具体的版本来安装内核代码(比如5.15.0-57-generic)或者预先下载好代码
1514

1615
apt-get build-dep linux linux-image-5.15.0-57-generic
1716

@@ -26,7 +25,11 @@ ubuntu解决安装包冲突问题
2625
apt-get install aptitude
2726
aptitude install <package-name>
2827

29-
安装代码(等价于下面的git命令)到/usr/src/linux目录下
28+
使用[docker](Dockerfile)来构建编译环境
29+
30+
docker build . -t bpf
31+
32+
下载代码(等价于下面的git命令)到/usr/src/linux目录下
3033

3134
apt-get -y source linux-image-unsigned-$(uname -r)
3235
==> git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
@@ -35,6 +38,10 @@ ubuntu解决安装包冲突问题
3538
ln -s $PWD /usr/src/linux
3639
cd /usr/src/linux
3740

41+
直接将预先下载好的代码映射到docker中
42+
43+
docker -v /path/to/linux:/usr/src/linux bpf /bin/bash
44+
3845
修改内核配置
3946

4047
chmod +x scripts/*
@@ -68,7 +75,9 @@ ubuntu解决安装包冲突问题
6875

6976
cd /usr/src/linux/samples/bpf && make
7077

71-
先要挂载对应的文件系统
78+
### 运行内核自带的用列
79+
80+
在运行环境中挂载对应的文件系统
7281

7382
mount -t bpf bpf /sys/fs/bpf
7483

@@ -97,7 +106,11 @@ get elm
97106
bpf: get fd:3 (Success)
98107
bpf: fd:3 l->(1):24 ret:(0,Success)
99108

100-
## 使用本demo
109+
## 使用本demo(using docker to compile)
110+
111+
将当前代码挂载到容器中
112+
113+
docker -v $PWD:/code -v /path/to/linux:/usr/src/linux bpf /bin/bash
101114

102115
在当前目录操作使用对应文件
103116

0 commit comments

Comments
 (0)