skip to Main Content

Hardware: Raspberry Pi 4B (linux/arm64/v8) – 4GB RAM & 64 GB SD card
OS: Ubuntu 20.04 LTS

TLDR

  • What can I do to build the image on my Pi without OOM?
  • Can I emulate a build from one of my AMD devices to build as ARM architecture for the Pi 4B to pull from DockerHub?

I want to build this Dockerfile and run the container for my drone-project. This is most efficient within the Pi itself but given the limited RAM on my Pi I get OOM half way through. I then tried to build the docker image on my stronger devices to push to DockerHub and pull to my Pi. However, these devices are AMD architecture so it didn’t work but the build took 12GB of RAM at peak.

What I tried:

nice -10 docker build DH_USER/autonomous-drone:vins-fusion .

  • I was hoping that nice -10 would provide some form of RAM throttling
  • I still get OOM due to RAM usage

docker buildx build --platform linux/arm64 -t DH_USER/autonomous-drone:vins-fusion .

  • I was hoping this would build properly for ARM architecture
  • at around 41% complete, I get c++: internal compiler error: Killed (program cc1plus)

2

Answers


  1. Chosen as BEST ANSWER

    As @datawookie suggested, I added a swap partition of 8Gb but this still crashed. I suspect this is due to my system running the desktop version of ubuntu rather than the CLI version. I had to also modify this line make -j$(USE_PROC) install && dockerfile_link and hardcode the processes to 1. This took a long time but eventually worked and then I pushed the image to DockerHub to make this faster in the future.


  2. To simulate your hardware setup I created a t2.medium instance running Ubuntu 20.04 on EC2. The instance has 4 GB RAM and a 24 GB root volume.

    If you want to build in this memory constrained environment then you need to find a way to provide the required memory space to the C++ compiler.

    You can do this by adding swap space. For example, this is what I did:

    SWAPFILE="/var/swap"
    SIZE=8G
    sudo fallocate -l $SIZE $SWAPFILE
    sudo chmod 600 $SWAPFILE
    sudo /sbin/mkswap $SWAPFILE
    sudo /sbin/swapon $SWAPFILE
    

    Now, in addition to 4 GB RAM I also have a chunk of swap. With this you can build the image. It will be slow when it comes to the memory intensive compile stages, but if you are patient (and it’s going to take around ~10 minutes) then you’ll end up with a working image (see screenshot below and note the free output at end showing RAM and swap space).

    Once you have built the image you can disable the swap and remove the swap file at /var/swap.

    sudo /sbin/swapoff $SWAPFILE
    sudo rm $SWAPFILE
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search