Manualy build arm elf docker image from scratch, run on X86 through qemu-arm-static/user mode

1. Build qemu static link user mode   Refer to https://blog.youkuaiyun.com/hushui/article/details/103806109


lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ file  qemu-aarch64
qemu-aarch64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=5b5ace3ac4f01e93e5ca6a695cbc8bb29669a53a, not stripped
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$  

 

2. ARM hello static link  or system call refer to https://raw.githubusercontent.com/docker-library/hello-world/master/hello.c


lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm/build$ export  PATH=~/opt/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/bin:$PATH
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm/build$ aarch64-linux-gnu-gcc --static -o hello  hello.c
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm/build$ file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=6c28f8fea781c9f640372fe4d04a0ce6f037ff92, not stripped
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm/build$ cd ..

lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ ls
Dockerfile  build  hello  qemu-aarch64  readme.txt
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ ls -l
total 14860
-rw-r--r-- 1 jhula sudo       74 Jan  9 22:57 Dockerfile
drwxr-xr-x 2 jhula sudo     4096 Jan  9 23:00 build
lrwxrwxrwx 1 jhula sudo       11 Dec  9 23:48 hello -> build/hello
-rwxr-xr-x 1 jhula sudo 15200568 Jan  9 22:55 qemu-aarch64
-rw-r--r-- 1 jhula sudo     2940 Dec 10 01:02 readme.txt 
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ ls -l
total 14860
-rw-r--r-- 1 jhula sudo       74 Jan  9 22:57 Dockerfile
drwxr-xr-x 2 jhula sudo     4096 Jan  9 23:03 build
lrwxrwxrwx 1 jhula sudo       11 Dec  9 23:48 hello -> build/hello
-rwxr-xr-x 1 jhula sudo 15200568 Jan  9 22:55 qemu-aarch64
-rw-r--r-- 1 jhula sudo     2940 Dec 10 01:02 readme.txt 

3.  local test  


lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ ./qemu-aarch64   ./build/hello
Hello

### Build Docker ARM ELF 
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ cat Dockerfile
FROM scratch
ADD hello /
ADD qemu-aarch64 /
CMD ["/qemu-aarch64","/hello"]
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ docker build -t hello-arm .
Sending build context to Docker daemon  20.09MB
Step 1/4 : FROM scratch
 --->
Step 2/4 : ADD hello /
 ---> Using cache
 ---> 419d850f28ac
Step 3/4 : ADD qemu-aarch64 /
 ---> Using cache
 ---> 797d466b2135
Step 4/4 : CMD ["/qemu-aarch64","/hello"]
 ---> Running in 919a8de0284f
Removing intermediate container 919a8de0284f
 ---> 37a6f5e5f93e
Successfully built 37a6f5e5f93e
Successfully tagged hello-arm:latest
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ docker ps -a |grep hello-arm
a9d28398f720        hello-arm                                                 "/qemu-aarch64 /hello"   2 minutes ago       Exited (0) 2 minutes ago                        pensive_babbage
lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$

4. ### Run Docker ARM image


lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$ docker run  hello-arm
Hello

lake@localhost:~/local/example-code/test-linux-docker-lake/myhello-arm$
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值