11

I try to build a Dockerfile and I get this :

Linking CXX executable ../../../../bin/clang
collect2: error: ld terminated with signal 9 [Killed]
make[2]: *** [bin/clang-3.2] Error 1
make[1]: *** [tools/clang/tools/driver/CMakeFiles/clang.dir/all] Error 2
make: *** [all] Error 2

Typically it means that I don't have enough memory. So how do I run docker build with a bigger memory (or swap ?)

Thanks :)

kondor
  • 783
  • 1
  • 8
  • 22

3 Answers3

28

Did you try increasing memory available for docker via Docker > Preferencess... > Advanced > Ram. It defaults to only 2 GB (on mac).

Cynic
  • 6,779
  • 2
  • 30
  • 49
  • 1
    This is what solved the problem for me. My docker build command was failing when compiling go modules, and bumping the memory (from the default of 2 to 5GB) solved the problem. Thanks! – pjam Jun 24 '21 at 15:02
4

When you are building the image docker has access to all the memory in the system.

I would recommend you not to compile while building the image, the union file system is slow and I have noticed it can run out of hard drive space pretty quickly.

What I do when I need to package an executable is to set up a container with all the necessary dependencies for compilation and then I run it with the source code mounted in a shared volume.

Once the code is compiled I move the executable into another folder where I have another Docker files that ADDs the executable into a minimal base image(like scratch or busy box).

By doing this I save time in compilation and I end up with a much smaller image.

Javier Castellanos
  • 9,346
  • 2
  • 15
  • 19
1

Buy a new RAM stick? :)

More seriously, you are probably running on a VM? You need to go change the settings of your virtual machine and increase the RAM size.

In VirtualBox, it is under Settings -> System -> Motherboard -> Base Memory.

By default, Docker has no memory limitation, so if you are out of memory, you need to increase the host's capacity.

creack
  • 116,210
  • 12
  • 97
  • 73