# Docker & swap space

**URL:** <https://forums.docker.com/t/docker-swap-space/3908>\
**Category:** General\
**Created:** [October 17, 2015, 3:40pm UTC](https://forums.docker.com/t/docker-swap-space/3908 "2015-10-17T15:40:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramnishkalsi](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@ramnishkalsi](https://forums.docker.com/u/ramnishkalsi)\
**Post date:** [October 17, 2015, 3:40pm UTC](https://forums.docker.com/t/docker-swap-space/3908/1 "2015-10-17T15:40:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ranjandas](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/ranjandas/32/2533_2.png) [@ranjandas](https://forums.docker.com/u/ranjandas)\
**Post date:** [October 18, 2015, 2:14am UTC](https://forums.docker.com/t/docker-swap-space/3908/2 "2015-10-18T02:14:34Z")

</div>

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.

```auto
# 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.

```auto
# 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](https://goo.gl/h60ico).

---

<div class="post-metadata">

**Author:** ![ramnishkalsi](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@ramnishkalsi](https://forums.docker.com/u/ramnishkalsi)\
**Post date:** [October 18, 2015, 12:40pm UTC](https://forums.docker.com/t/docker-swap-space/3908/3 "2015-10-18T12:40:32Z")

</div>

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.
