gpt4 book ai didi

Docker 容器不从主机继承 ulimit

转载 作者:行者123 更新时间:2023-12-02 18:16:41 25 4
gpt4 key购买 nike

我已阅读 here docker 容器从主机继承 ulimit 属性。我的容器似乎没有发生这种情况。特别是,我需要从主机继承 max locked memory 属性。有谁知道如何修复它?

ubuntu@host:~$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 31404
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 50000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 50000
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
ubuntu@host:~$ docker exec -it container /bin/bash
root@container:/# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 31404
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 524288
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 524288
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

最佳答案

如果要为容器设置自定义 ulimit,可以使用 --ulimit 选项。例如;

docker run -it --rm --ulimit memlock=32768:32768 ubuntu sh -c "ulimit -a"

显示:

time(seconds)        unlimited
file(blocks) unlimited
data(kbytes) unlimited
stack(kbytes) 8192
coredump(blocks) 0
memory(kbytes) unlimited
locked memory(kbytes) 32
process 7873
nofiles 1024
vmemory(kbytes) unlimited
locks unlimited

您可以在文档中找到更多信息; https://docs.docker.com/engine/reference/commandline/run/

有关限制容器资源的其他方法,另请参阅本节; https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources

关于Docker 容器不从主机继承 ulimit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36298913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com