I am running a centos7 unprivileged LXD container on a ubuntu 17.04 host. I have a problem setting ulimit for NOFILE inside the container, if it is running in unprivileged mode.
Bellow are the steps to reproduce:
$ lxc launch images:centos/7/amd64 mycontainer
$ lxc exec mycontainer bash
[root@mycontainer ~]# yum install strace
[root@mycontainer ~]# ulimit -n 200000
bash: ulimit: open files: cannot modify limit: Operation not permitted
[root@mycontainer ~]#
[root@mycontainer ~]# strace -e setrlimit bash -c 'ulimit -n 200000'
setrlimit(RLIMIT_NOFILE, {rlim_cur=200000, rlim_max=200000}) = -1 EPERM (Operation not permitted)
bash: line 0: ulimit: open files: cannot modify limit: Operation not permitted
+++ exited with 1 +++
[root@mycontainer ~]#
Configuration details of the container:
$ sudo lxc config show mycontainer
architecture: x86_64
config:
image.architecture: amd64
image.build: "20170504_02:16"
image.description: Centos 7 (amd64) (20170504_02:16)
image.distribution: centos
image.release: "7"
volatile.base_image: 41c7bb494bbdf71c2aee471bb44a2318fd3424a0cd22091fb896a7614ae545eb
volatile.eth0.hwaddr: 00:16:3e:61:e4:6c
volatile.eth0.name: eth0
volatile.idmap.base: "0"
volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":140000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":140000,"Nsid":0,"Maprange":65536}]'
volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":140000,"Nsid":0,"Maprange":65536},{"Isuid":false,"Isgid":true,"Hostid":140000,"Nsid":0,"Maprange":65536}]'
volatile.last_state.power: STOPPED
volatile.root.hwaddr: 00:16:3e:6b:93:1d
volatile.root.name: eth1
devices: {}
ephemeral: false
profiles:
- default
As a workaround I can make the container privileged, but I prefer to grant only rlimit access for this container, or to be able to rise the limit from lxd. Here is how I set in to be privileged:
$ lxc config set mycontainer security.privileged true
$ lxc restart mycontainer
$ sudo lxc config show mycontainer
architecture: x86_64
config:
image.architecture: amd64
image.build: "20170504_02:16"
image.description: Centos 7 (amd64) (20170504_02:16)
image.distribution: centos
image.release: "7"
security.privileged: "true"
volatile.base_image: 41c7bb494bbdf71c2aee471bb44a2318fd3424a0cd22091fb896a7614ae545eb
volatile.eth0.hwaddr: 00:16:3e:61:e4:6c
volatile.eth0.name: eth0
volatile.idmap.base: "0"
volatile.idmap.next: '[]'
volatile.last_state.idmap: '[]'
volatile.last_state.power: RUNNING
devices: {}
ephemeral: false
profiles:
- default
It seems that there is an option in development to set the limits from lxd:
The solution will be:
See: