1

When building a Docker image, there's some compilations of C++ scripts and I ended up with errors like:

src/amun/CMakeFiles/cpumode.dir/build.make:134: recipe for target 'src/amun/CMakeFiles/cpumode.dir/cpu/decoder/encoder_decoder_state.cpp.o' failed
virtual memory exhausted: Cannot allocate memory

But when building the same .cpp code on the host machine, it works fine.


After some checking, the error message seems to be similar to the one that people get on a Raspberry Pi, https://www.bitpi.co/2015/02/11/how-to-change-raspberry-pis-swapfile-size-on-rasbian/

And after some more googling, this post on the Mac forum says that:

Swapfiles are dynamically created as needed, until either the disk is full, or the kernel runs out of page table space. I do not think you can change the page table space limits in the Mac OS X kernel. I have not seen anything in all the years I've been using OS X.

Is there a way to increase the swap space for Docker build on Mac OS?

If not, how else can be done to overcome the "virtual memory exhausted" error when building a Docker image?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
alvas
  • 115,346
  • 109
  • 446
  • 738
  • You'll want to clarify which docker implementation you're using on macos. For example with boot2docker you'll want to adjust the memory granted to the virtualbox vm – anthony sottile Aug 11 '17 at 03:47

2 Answers2

3

That does not seem trivial to do with XHyve.
As stated in this thread

I think the default size of the VM is 16GB. I kept running out of swap space even after bumping the ram on the VM up to 16GB.

Check if the method used for a VirtualBox VM would apply in XHyve: see "How to increase the swap space available in the boot2docker virtual machine?"

boot2docker ssh

export SWAPFILE=/mnt/sda1/swapfile
sudo dd if=/dev/zero of=$SWAPFILE bs=1024 count=4194304
sudo mkswap $SWAPFILE
sudo chmod 600 $SWAPFILE
sudo swapon $SWAPFILE

exit

Check also this Digital Ocean Setup, again to test in your XHyve context.
mkswap is also seen here or in docker-root-xhyve/contrib/makehdd/makehdd.sh.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Since you have enough available memory in your host, I recommend you to assign more memory to the Docker VM that is behind.

As stated here:

As I can see that you are on OSX, which runs docker over a Linux VM. Configure the max memory clicking the whale icon in the task bar. By default is 2G.

For further information: https://docs.docker.com/docker-for-mac/#memory

enter image description here

Robert
  • 33,429
  • 8
  • 90
  • 94