Skip to content

Allow setting ulimits for containers - #9437

Merged
jessfraz merged 1 commit into
moby:masterfrom
cpuguy83:set_rlimits_in_container
Mar 4, 2015
Merged

jessfraz merged 1 commit into
moby:masterfrom
cpuguy83:set_rlimits_in_container

Conversation

@cpuguy83

@cpuguy83 cpuguy83 commented Dec 1, 2014

Copy link
Copy Markdown
Member

Closes #4717

Add option to set ulimit settings for containers.
Currently the container inherits from the daemon's ulimit settings.

Support for this was added in libcontainer here docker-archive/libcontainer@7ce34f5

@cpuguy83
cpuguy83 force-pushed the set_rlimits_in_container branch from 46ffe5a to 8036187 Compare December 1, 2014 18:44

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintended wrapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that would be the output of the run command.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, mis-interpreted, I thought -n 1024 😄

@crosbymichael

Copy link
Copy Markdown
Contributor

I like it LGTM

@SvenDowideit

Copy link
Copy Markdown
Contributor

Doc LGTM - @fredlf @jamtur01

it might be good to add what happens if you try to set a limit in the container that is larger than that on the host.

@cpuguy83

cpuguy83 commented Dec 2, 2014

Copy link
Copy Markdown
Member Author

@SvenDowideit I think it doesn't matter since Docker is setting the limit, which has full host access.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the super nitpicky remark, but I don't think the trailing comma is legal JSON.

@cpuguy83 cpuguy83 mentioned this pull request Dec 2, 2014

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...they will be inherited"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check to make sure you are consistent with code style for all instances of ulimit.

@fredlf

fredlf commented Dec 2, 2014

Copy link
Copy Markdown
Contributor

Docs LGTM, though I would like that one point clarified, ideally. Thanks.

@cpuguy83
cpuguy83 force-pushed the set_rlimits_in_container branch from 61fa833 to 9681336 Compare December 3, 2014 18:33
@cpuguy83

cpuguy83 commented Dec 3, 2014

Copy link
Copy Markdown
Member Author

@fredlf Updated.

@jamtur01

jamtur01 commented Dec 9, 2014

Copy link
Copy Markdown
Contributor

LGTM

1 similar comment
@fredlf

fredlf commented Dec 10, 2014

Copy link
Copy Markdown
Contributor

LGTM

@fredlf

fredlf commented Dec 10, 2014

Copy link
Copy Markdown
Contributor

@cpuguy83 I'll merge if you can address the conflicts.

@lexinator

Copy link
Copy Markdown

@SvenDowideit

Copy link
Copy Markdown
Contributor

@lexinator doesn't really apply, as this project only uses the merge-pull-request-button - and if you're involved enough that its a problem, you can request a change to the project's processes via PR :)

we also have a policy of taking over and updating PR's for contributors - but @cpuguy83 is a pretty core contributor, so :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to revert changes to v1.16 and add apply them to v1.17 now.

@icecrime

Copy link
Copy Markdown
Contributor

Talked with @crosbymichael: we believe this would get merged if you submitted an implementation. Do you want to close this one and make a new PR when ready, or add new commits here?

@cpuguy83
cpuguy83 force-pushed the set_rlimits_in_container branch from 9681336 to 61445a5 Compare January 14, 2015 01:51
@jeremyeder

Copy link
Copy Markdown

I plan to test this when there's code.

@cpuguy83

Copy link
Copy Markdown
Member Author

Working on it. I'll put commits here.

@cpuguy83
cpuguy83 force-pushed the set_rlimits_in_container branch from 61445a5 to d407d43 Compare January 14, 2015 22:42
@cpuguy83

Copy link
Copy Markdown
Member Author

Ok, it's done, tear it up!

Note, I changed the the HostConifg->Ulimits field to be an array instead of map.

@cpuguy83
cpuguy83 force-pushed the set_rlimits_in_container branch from d407d43 to 4a63d3f Compare January 14, 2015 22:44
@philips

philips commented Feb 26, 2015

Copy link
Copy Markdown
Contributor

@cpuguy83 makes sense, I see it in the docs now, no idea how I missed that. Thanks.

@jessfraz

jessfraz commented Mar 4, 2015

Copy link
Copy Markdown
Contributor

what is this waiting on?

@liquid-sky

Copy link
Copy Markdown

How can one provide RLIM_INFINITY value as per resource.h or equivalent of providing unlimited value when running ulimit for a resource?

@cpuguy83

Copy link
Copy Markdown
Member Author

@liquid-sky it is unsupported. There really isn't an unlimited, it's just a really high value.

@frol

frol commented Apr 23, 2015

Copy link
Copy Markdown

UPDATE: It seems that ulimit subsystem is not namespaced and applies limits to all processes based only on UID/GID.

Original post:

I cannot figure out why it happens, but it seems that resources that are limited by ulimit are counted across containers. Here is an example:

If I run one container with --ulimit 'nproc=2' it runs fine, but I cannot start the second container with the same --ulimit 'nproc=2':

Terminal #1:

$ docker run -it --rm --ulimit 'nproc=2' --user nobody debian bash
nobody@7005f259a827:/$

Terminal #2:

$ docker run -it --rm --ulimit 'nproc=2' --user nobody debian bash
resource temporarily unavailable
FATA[0000] Error response from daemon: Cannot start container 589299c070779487462393fcb04df05d619d2debe1b1197c41587ee53c2283b8: [8] System error: resource temporarily unavailable

I tested this on Ubuntu 14.04 (kernel 3.16) and Ubuntu 12.04 (kernel 3.13), Docker 1.6.0.

@cpuguy83

Copy link
Copy Markdown
Member Author

After some digging, it seems nproc is special and is per user.

@frol

frol commented Apr 23, 2015

Copy link
Copy Markdown

Note: another part of discussion is going in #6479 (Fork bomb prevention) and will probably continue there.

@ashish235

Copy link
Copy Markdown

So how to set the Ulimit? Can it be done per container wise? I seem to be clueless with the discussions happening in this thread.. Can someone help please.
I need "ulimit -c unlimited" equivalent for docker.

@ashish235

Copy link
Copy Markdown

[root@localhost ~]# docker run --ulimit core=unlimited -t ubuntu:12.04 bash -c "ulimit -c"
invalid value "core=unlimited" for flag --ulimit: strconv.ParseInt: parsing "unlimited": invalid syntax
See 'docker run --help'.

Unlimited is not a recognized keyword here.

My docker version is the latest 1.7.

[root@localhost ~]# docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): ba1f6c3/1.6.2
OS/Arch (client): linux/amd64
INFO[0203] GET /v1.18/version
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64

Also setting big values doesn't help here.

[root@localhost ~]# docker run --ulimit core=99999 -t ubuntu:12.04 bash -c "ulimit -c"
97

It sets only 97.

@thaJeztah

Copy link
Copy Markdown
Member

Hi @ashish235 please keep in mind that GitHub is an issue tracker, and not a general support forum.

A number of things I noticed; first of all, although your daemon is 1.7.1, your client is still at 1.6.2, so you might want to update that as well.

There were some fixes to ulimits in docker 1.7.x, but I'm not sure if those fixes were in the client or daemon, so this may be worth checking. (#12515)

W.r.t. "unlimited"; #12515 (comment)

unlimited is purposefully not support since it's not a real value, it's just a constant set to a really high number.

W.r.t. "setting big values doesn't help here"; please note this comment: #12957 (comment)

It sets the limit value as number of bytes, while ulimit reports the number of kb. So 32768 bytes == 32 kb

Converting 99999 to kb; https://www.google.com/search?q=99999%20bytes%20in%20kibibyte I get "97", so this looks right

shimaore added a commit to shimaore/ccnq4-opensips that referenced this pull request Dec 7, 2015
First attempt: most probably Docker.io would not honor the values in /etc/security etc. so this would not work:

    # Core Generation: http://www.opensips.org/Documentation/TroubleShooting-Crash
    RUN \
      echo -n -e 'opensips soft core unlimited\nopensips hard core unlimited\n' >> /etc/security/limits.conf \
      && \
      echo -n -e 'fs.suid_dumpable = 1\nkernel.core_uses_pid = 1\n' >> /etc/sysctl.conf

See e.g. moby/moby#9437
@AkihiroSuda

Copy link
Copy Markdown
Member

@cpuguy83 @cyphar @giuseppe

Do you think we can add support for RLIMIT_AS for rootless mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sysctl tunables