Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow more memory when docker build a Dockerfile

Tags:

docker

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 :)

like image 252
kondor Avatar asked Nov 13 '14 16:11

kondor


3 Answers

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

like image 85
Cynic Avatar answered Oct 03 '22 19:10

Cynic


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.

like image 22
Javier Castellanos Avatar answered Oct 03 '22 19:10

Javier Castellanos


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.

like image 44
creack Avatar answered Oct 03 '22 19:10

creack