在 x86 Docker 中交叉编译 ARM 代码教程

在 x86 Docker 中交叉编译 ARM 代码教程

文章目录

    • 在 x86 Docker 中交叉编译 ARM 代码教程
      • 在ubuntu上安装docker
      • 安装multiarch/qemu-user-static
      • 安装arm32v7/ubuntu:16.04
      • 用multiarch/qemu-user-static运行arm32v7/ubuntu:16.04文件系统
      • 在 x86 Docker 中交叉编译 ARM 代码(以编译开源spdlog为例)
      • 【附件】Ubuntu Docker 安装的方法
      • 【附件】卸载 docker的方法
      • 【附件】查找rk3288镜像的方法
      • 【附件】安装rk3288镜像的方法
      • 【附件】查看镜像的方法的方法
      • 【附件】删除镜像的方法
      • 【附件】启动rk3288容器的方法
      • 【附件】自己制作RK3288镜像
      • 【附件】docker容器和PC之间互相拷贝文件

在ubuntu上安装docker

#安装 Docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

#测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:
ubuntu@ubuntu:~$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
。。。。。。。。。。。。。。。。。。。。。。。。

安装multiarch/qemu-user-static

#安装multiarch/qemu-user-static
ubuntu@ubuntu:~$ sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

安装arm32v7/ubuntu:16.04

#安装arm32v7/ubuntu:16.04
ubuntu@ubuntu:~$ sudo docker run --rm -t arm32v7/ubuntu:16.04 uname -m

用multiarch/qemu-user-static运行arm32v7/ubuntu:16.04文件系统

#####################################################################################################################
#用multiarch/qemu-user-static运行arm32v7/ubuntu:16.04文件系统
ubuntu@ubuntu:~$ sudo docker run -it --rm -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static arm32v7/ubuntu:16.04 bash


#####################################################################################################################
#进入arm32v7/ubuntu:16.04文件系统
root@2b1807b809ae:/# 
root@2b1807b809ae:/# uname -a
Linux 2b1807b809ae 4.15.0-142-generic #146~16.04.1-Ubuntu SMP Tue Apr 13 09:27:15 UTC 2021 armv7l armv7l armv7l GNU/Linux
root@2b1807b809ae:/# ls /
bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

在 x86 Docker 中交叉编译 ARM 代码(以编译开源spdlog为例)

#进入arm32v7/ubuntu:16.04文件系统
root@2b1807b809ae:/# 
root@2b1807b809ae:/# uname -a
Linux 2b1807b809ae 4.15.0-142-generic #146~16.04.1-Ubuntu SMP Tue Apr 13 09:27:15 UTC 2021 armv7l armv7l armv7l GNU/Linux
root@2b1807b809ae:/# ls /
bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@2b1807b809ae:/# cd home/
root@a6284dd733d2:/home#
root@a6284dd733d2:/home# mkdir src
root@a6284dd733d2:/home# cd src/
root@a6284dd733d2:/home/src# apt update
root@a6284dd733d2:/home/src# apt autoremove
root@a6284dd733d2:/home/src# apt autoclean
root@a6284dd733d2:/home/src# apt install git vim g++ make cmake
root@a6284dd733d2:/home/src# apt install -y liblua5.3-dev libeigen3-dev libmxml-dev libyaml-cpp-dev
root@a6284dd733d2:/home/src# apt install -y qt5-default qt5-qmake
root@a6284dd733d2:/home/src# apt install libqt5webkit5-dev
root@a6284dd733d2:/home/src# dpkg-reconfigure dash
#选择no
root@a6284dd733d2:/home/src# echo $SHELL
/bin/bash
root@a6284dd733d2:/home/src# cd ./docs/spdlog/
root@a6284dd733d2:/home/src/docs/spdlog# mkdir build
root@a6284dd733d2:/home/src/docs/spdlog# cd build
root@a6284dd733d2:/home/src/docs/spdlog/build# cmake ..
root@a6284dd733d2:/home/src/docs/spdlog/build# make -j4
root@a6284dd733d2:/home/src/docs/spdlog/build# make install

【附件】Ubuntu Docker 安装的方法

安装命令如下:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:

ubuntu@ubuntu:~$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
。。。。。。。。。。。。。。。。。。。。。

【附件】卸载 docker的方法

删除安装包:

sudo apt-get purge docker-ce

删除镜像、容器、配置文件等内容:

sudo rm -rf /var/lib/docker

【附件】查找rk3288镜像的方法

ubuntu@ubuntu:~$ sudo docker search rk3288
NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
deviceon/rk3288-build-rmm                                                      0                    
terrycmchan/rk3288linux        Images for building Rockchip RK3288 Linux SD…   0                    
ecgwc/rk3288-build-rmm                                                         0                    
terrycmchan/rk3288android      Images for building Rockchip RK3288 Android …   0                    
advrisc/u16.04-rk3288lbv1      RK3288 Linux Docker                             0                    
advrisc/u14.04-rk3288abv1      docker image for rk3288                         0                    [OK]
yangzhengguang/u14.04_rk3288   docker image for rk3288                         0                    [OK]

【附件】安装rk3288镜像的方法

ubuntu@ubuntu:~$ sudo docker pull advrisc/u16.04-rk3288lbv1
Using default tag: latest
latest: Pulling from advrisc/u16.04-rk3288lbv1
7b722c1070cd: Pull complete 
。。。。。。。。。。。。。。。

【附件】查看镜像的方法的方法

ubuntu@ubuntu:~$ sudo docker images
[sudo] hrg 的密码:
REPOSITORY                   TAG       IMAGE ID       CREATED        SIZE
multiarch/qemu-user-static   latest    871019ea8dda   4 weeks ago    299MB
hello-world                  latest    feb5d9fea6a5   2 months ago   13.3kB
arm32v7/ubuntu               16.04     033c410d53ef   3 months ago   106MB

【附件】删除镜像的方法

镜像删除使用 docker rmi 命令,比如我们删除rk3288_ubuntu_1604 镜像:

ubuntu@ubuntu:~$ sudo docker images
REPOSITORY                  TAG       IMAGE ID       CREATED        SIZE
my/rk3288_ubuntu_1604       v1.0.1    ba6acccedd29   5 weeks ago    72.8MB
hello-world                 latest    feb5d9fea6a5   2 months ago   13.3kB
ubuntu                      16.04     b6f507652425   2 months ago   135MB
advrisc/u16.04-rk3288lbv1   latest    7a4ba43f5b0c   2 years ago    1.38GB
ubuntu@ubuntu:~$ sudo docker rmi my/rk3288_ubuntu_1604
Error: No such image: my/rk3288_ubuntu_1604
ubuntu@ubuntu:~$ sudo docker rmi my/rk3288_ubuntu_1604:v1.0.1
Untagged: my/rk3288_ubuntu_1604:v1.0.1
Deleted: sha256:ba6acccedd2923aee4c2acc6a23780b14ed4b8a5fa4e14e252a23b846df9b6c1
Deleted: sha256:9f54eef412758095c8079ac465d494a2872e02e90bf1fb5f12a1641c0d1bb78b

【附件】启动rk3288容器的方法

以下命令使用 ubuntu 镜像启动一个容器,参数为以命令行模式进入该容器:

ubuntu@ubuntu:~$ sudo docker run -t -i advrisc/u16.04-rk3288lbv1 /bin/bash
adv@d55f3018690e:~$ cd /
adv@d55f3018690e:/$ ll
ll: command not found
adv@d55f3018690e:/$ ls
bin  boot  dev	etc  home  lib	lib32  lib64  libx32  media  mnt  opt  proc  python-support_1.0.15_all.deb  root  run  sbin  srv  sys  tmp  usr  var
adv@d55f3018690e:/$ df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay         176G  121G   47G  73% /
tmpfs            64M     0   64M   0% /dev
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
shm              64M     0   64M   0% /dev/shm
/dev/sda1       176G  121G   47G  73% /etc/hosts
tmpfs           3.9G     0  3.9G   0% /proc/asound
tmpfs           3.9G     0  3.9G   0% /proc/acpi
tmpfs           3.9G     0  3.9G   0% /proc/scsi
tmpfs           3.9G     0  3.9G   0% /sys/firmware
adv@d55f3018690e:/$ exit
exit
ubuntu@ubuntu:~$ 

#查看容器
ubuntu@ubuntu:~$ sudo docker ps
CONTAINER ID   IMAGE                  COMMAND   CREATED       STATUS       PORTS     NAMES
a6284dd733d2   arm32v7/ubuntu:16.04   "bash"    3 hours ago   Up 3 hours             dazzling_merkle

【附件】自己制作RK3288镜像

ubuntu@ubuntu:~/devel/root_rk3288$ ls
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  root_rk3288_16.04  rp_test  run  sbin  snap  srv  sys  system  tmp  usr  var
ubuntu@ubuntu:~/devel/root_rk3288$ touch Dockerfile
ubuntu@ubuntu:~/devel/root_rk3288$ gedit Dockerfile 
#################################################################
##注解
FROM aarch64/ubuntu:16.04
#################################################################
ubuntu@ubuntu:~/devel/root_rk3288$ sudo docker build -t='my/rk3288_ubuntu_1604:v1.0.1' . 

ubuntu@ubuntu:~/devel/root_rk3288$ sudo docker build -t='my/rk3288_ubuntu_1604:v1.0.1' . 
[sudo] password for ubuntu: 
ERRO[0036] Can't add file /home/ubuntu/devel/root_rk3288/home/rpdzkj/.gnupg/S.gpg-agent to tar: archive/tar: sockets not supported 
ERRO[0043] Can't add file /home/ubuntu/devel/root_rk3288/tmp/.ICE-unix/1042 to tar: archive/tar: sockets not supported 
ERRO[0043] Can't add file /home/ubuntu/devel/root_rk3288/tmp/.X11-unix/X0 to tar: archive/tar: sockets not supported 
Sending build context to Docker daemon  5.314GB
Step 1/1 : FROM ubuntu
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete 
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
 ---> ba6acccedd29
Successfully built ba6acccedd29
Successfully tagged my/rk3288_ubuntu_1604:v1.0.1
ubuntu@ubuntu:~/devel/root_rk3288$ 

【附件】docker容器和PC之间互相拷贝文件

#在ubuntu下另起一个shell,其中“a6284dd733d2”是arm32v7/ubuntu:16.04容器的ID【在docker中的命令行显示“root@0bf7162981ce:/home/src/#”其中“0bf7162981ce”即是docker容器的ID】

#PC拷贝到docker容器:
hrg@hrg-PowerEdge-T440:~$ sudo docker cp /home/build.sh 0bf7162981ce:/home/src/


#docker容器拷贝到PC:
ubuntu@ubuntu:~$ sudo docker cp 0bf7162981ce:/home/src/build.sh ./


你可能感兴趣的:(Linux,ARM,ROS,docker,linux,ubuntu,arm开发)