Docker & swap space

Hi - I am building a docker image however it seems I am now stuck at a swap issue.

The ‘docker build’ command fails at Step 51 mentioned below. Basically it is a silent install for an oracle product. The problem happens because of swap space.

I tried to increase the swap space, using directions in Addendum A below, but I get into privilege issues (Addendum B)

Any pointers ?

Thanks.


Step 51 : RUN su -m endeca -c ‘$BASE_TMP_ENDECA_INSTALL/cd/Disk1/install/silent_install.sh silent_response.rsp ToolsAndFrameworks $BASE_ENDECA_DIR/ToolsAndFrameworks admin’
—> Running in db8e9f1acc60
Starting Oracle Universal Installer…

Checking swap space: 398 MB available, 500 MB required. Failed <<<<

Some requirement checks failed. You must fulfill these requirements before


Addendum A
sudo install -o root -g root -m 0600 /dev/null /swapfile
dd if=/dev/zero of=/swapfile bs=1k count=1024k
mkswap /swapfile
swapon /swapfile
echo “/swapfile swap swap auto 0 0” | sudo tee -a /etc/fstab
sudo sysctl -w vm.swappiness=10
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Addendum B
[root@4fcf25a42c86 /]# swapon /swapfile
swapon: /swapfile: swapon failed: Operation not permitted

Hi,

As each running docker container uses the host Kernel, they also use the memory and swap of the host. If this is a one of requirement its better to increase the host swap space.

If you want to still add swap from the container you have two options.

  • Run container in privileged mode
    In this case you will have to run the container with --privileged option.
# Example
docker run -it --rm --privileged centos:6
  • Running container with privileged mode gives container full privilege on the host. If you read the manpage of swapon you can see that for swapon to run the process should have CAP_SYS_ADMIN capability. In Docker you can add a particular capability selectively to the container using the --cap-add argument.
# Example
docker run -it --rm --cap-add SYS_ADMIN centos:6

If you run the container in either of the above two modes you can achieve what you are trying.

Now the problem with this approach is , when you create swap inside the container and start using that, its actually the Host Kernel that is using it, as a result when you exit the container without a swapoff the host kernel will be still using the file, and you wont get a clean exit of the container. You will see a dead status for the container.

Hope this helps. The following link helped me in understanding this, https://goo.gl/h60ico.

2 Likes

Thanks for the detailed reply. Much appreciated.

I am on a Mac, so that would mean the linux VM that the docker is running on ?

That default Virtual box VM is created when
’/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh’
is run.

How do i change the swap in that VM ? (if it is the right one).

Thanks again.