Joachim Breitner
Joachim Breitner

Reputation: 25782

Cannot reduce ulimits inside docker container

I want to use ulimit -f inside a docker container to reduce the limits. (I stress this as many questions and answers around this involve increasing limits).

I have a script that writes a 10k file, and reports successs:

$ perl examples/largefile.pl
Begin
End

I can prevent it from running to completion, as expected, with ulimit -f:

$ ( ulimit -f 5 ; perl examples/largefile.pl )
Begin

Unfortunately, inside a cocker container, the ulimit -f command doesn’t seem to haven an effect:

$ sudo docker run --rm -i -t -u 1001 -v $PWD:$PWD safe-docker bash
user@08aba80ebaff:/$ cd ...
user@08aba80ebaff:/...$ examples/largefile.pl
Begin
End
user@08aba80ebaff:/...$ ( ulimit -f 5 ; perl examples/largefile.pl )
Begin
End

but note how ulimit believes it had an effect:

user@08aba80ebaff:/...$ ( ulimit -f; ulimit -f 5; ulimit -f)
unlimited
5

Passing --privileged to docker run does not help.

This is related to my earlier question, but there I wonder about inheriting limits from the caller to docker run, whereas here I wonder about setting limits inside the container.

Upvotes: 1

Views: 581

Answers (1)

Joachim Breitner
Joachim Breitner

Reputation: 25782

It seems that this was recently implemented in docker: https://github.com/docker/docker/issues/4717

Upvotes: 1

Related Questions