Long time, no post. That’s what we call holidays. Anyways, here’s how to increase the size of swap available in Docker.

When you try to set up an OracleDB inside a docker container, you’ll probably need this.

This works only with the native virtualization version of Docker for Mac. If you still use boot2docker, you need to follow the guide in this issue.

This guide was updated in February 2018 because Docker has changed the underlying VM. (more info)

Nowadays changing the swap size is possible in the Docker Desktop settings.

  1. Open any terminal, make sure that screen is installed (use Homebrew)
  2. Connect to the Docker VM:
    screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
    
  3. You might need to press enter or login to show the prompt. The username is root and the password is empty.
  4. Create a new swapfile:
    dd if=/dev/zero of=/var/lib/swapfile count=2000000 bs=1024
    
  5. Change the permissions and run mkswap:
    chmod go= /var/lib/swapfile && mkswap /var/lib/swapfile
    
  6. Activate the swap:
    swapon -v /var/lib/swapfile
    
  7. Hold ctrl and press a followed by d to detach the screen session.

Note that you’ll lose the swap, when the machine is recreated or you restart Docker.

In this case you’ll just need to repeat steps two and six to eight, because the swapfile is still present (unless you completely recreated the Docker machine).