1. 程式人生 > >Docker sched_setscheduler() failed: Operation not permitted解決方案

Docker sched_setscheduler() failed: Operation not permitted解決方案

Docker容器在預設執行的時候由於安全原因,限制了一些功能,如果需要開啟需在執行時進行配置。

要使用實時排程需要 --cpu-rt-runtime 來執行容器。

sched_setscheduler()函式要求sys_nice能力,Docker容器在執行的時候預設是不開啟的。

所以需要在執行的時候執行:docker run -ti --cpu-rt-runtime=95000 --ulimit rtprio=99 --cap-add=sys_nice ubuntu

在使用上述命令是可能會遇到錯誤cpu-rt-runtime寫入失敗,原因是cgroup parent 的cpu-rt-runtime比你要修改的小。

執行 docker run -it --privileged --pid=host ubuntu nsenter -t 1 -m

cd /sys/fs/cgroup/cpu/docker 

檢視 cpu.rt_runtime_us是多少

cat cpu.rt_runtime_us

將它修改為950000

echo 950000>cpu.rt_runtime_us

緊接著再執行

docker run -ti --cap-add=sys_nice --cpu-rt-runtime --ulimit rtprio=99 ubuntu

就搞定啦

參考文章:https://github.com/moby/moby/pull/23430

https://github.com/moby/moby/issues/22380