Unprivileged lxc containers and open file limit problem

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

If you’re running unprivileged lxc containers, you will notice that some software fail to install or start. For example, you may have this kind of problem on Ubuntu, when trying to install mongo:

root@mongo-test-0001:~# apt-get -f mongodb-org
(...)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mongodb-org-server (2.6.10) ...
start: Job failed to start
invoke-rc.d: initscript mongod, action "start" failed.
dpkg: error processing package mongodb-org-server (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mongodb-org:
 mongodb-org depends on mongodb-org-server; however:
  Package mongodb-org-server is not configured yet.

dpkg: error processing package mongodb-org (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mongodb-org-server
 mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)


The problem is the following line in /etc/init/mongod.conf:

limit nofile 64000 64000

Because it’s an unprivileged lxc container, even root is not able to increase open files limit to 64000 in the guest!


The solution is to add these lines in /etc/security/limits.conf on the host (you’ll have to stop the guest, log out / log in to your shell for the change to have effect):

# adjusted for lxc
*               hard    nofile          65536
*               soft    nofile          65000

After this, start the guest again, problem should be solved:

root@mongo-test-0001:~# apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mongodb-org-server (2.6.10) ...
Setting up mongodb-org (2.6.10) ...