Docker for Mac - Increase Swap

September 30, 2017

docker, mac, oracle

In an attempt to compare how long it will take to build a Docker image of Oracle XE (11.2) vs EE (12.2) on my Mac I ran into a problem. The building of XE failed, it complained that only 1023 MB swap space was available. I thought that adding swap during build with this workaround would do, but it turns out that with Docker things are different.

I found suggestions here , but since I was not reading carefully enough, I missed the point that you add swap to the hypervisor Docker for Mac is running on. This is what I did to solve it. You connect to the hypervisor with:

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

In my case it did not ask for a password, you get connected as root. Just apply the normal procedure to add swap temporarily:

dd if=/dev/zero of=/var/swap.file count=2000000 bs=1024
chmod 0600 /var/swap.file
mkswap /var/swap.file
echo "/var/swap.file swap swap defaults 0 0" >> /etc/fstab
swapon -a

Disconnect with Ctrl-A d. Start the building again with:

./ -v -x  

The change above is not permanent. After a restart of Docker, you can check with free -m (when connected to the hypervisor) that available swap space is down to 1023MB.

By the way, I am using Docker for Mac, check out a comparison of Docker for Mac vs Docker Toolbox

It is worth pointing out that while Docker Toolbox used a VirtualBox VM, Docker for Mac uses Hyperkit , a lightweight macOS virtualization solution built on top of Hypervisor.framework in macOS 10.10 Yosemite and higher.

Another strange issue was that when I connected with screen a second time, the terminal was a complete mess. After a restart of Docker, the terminal was OK.

To start the XE container I used the following command:

docker run -d -p 15210:1521 --name oracle-xe --shm-size=2g oracle/database:

Without the shm-size option it will fail:

Error: The container doesn't have enough memory allocated.
A database XE container needs at least 1 GB of shared memory (/dev/shm).
You currently only have 64 MB allocated to the container.

Here I used the option -d, in order to run it in the background. Use this command to see the progress of the database creation:

docker logs -ft oracle-xe

I also forward the standard 1521 port to 15210 since 1521 is likely occupied with something else.

Last tip: SQL Developer Command Line version is very lightweight and useful when testing this, you probably can’t get connected faster than this:

./sql system/ede49171a7c0349c@localhost:15210/XE

(For once I am not worried about sharing a password, they are generated for each new container.)