简体   繁体   English

如何在Docker中挂载Hugepages

[英]How to Mount Hugepages inside Docker

I have an application running inside Docker requires Huge-page to run .Now I tried following set of command for same. 我有一个在Docker内部运行的应用程序,需要Huge-page才能运行。现在我尝试按照以下命令进行设置。

CMD ["mkdir", "-p" ,"/dev/hugepages"]
CMD ["mount" ,"-t", "hugetlbfs" , "none", "/dev/hugepages"]
CMD ["echo 512" ,">" ,"/proc/sys/vm/nr_hugepages"]
CMD ["mount"]

But I don't see Hugepages gets mounted from mout command, why? 但我看不到mout命令挂载Hugepages,为什么?

Could anyone please point me out, is it possible to do it? 任何人都可以指出我,可以这样做吗?

There's a number of things at hand; 有很多东西在手;

First of all, a Dockerfile only has a single command ( CMD ); 首先,一个Dockerfile仅具有单个命令( CMD ); what you're doing won't work; 你在做什么是行不通的; if you need to do multiple steps when the container is started, consider using an entrypoint script, for example this is the entrypoint script of the official mysql image 如果启动容器时需要执行多个步骤,请考虑使用入口点脚本,例如, 这是官方mysql映像的入口点脚本。

Second, doing mount in a container requires additional privileges. 其次,在容器中进行mount需要其他特权。 You can use --privileged but that is probably far too wide of a step, and gives far too much privileges to the container. 您可以使用--privileged但是这可能一步之遥,并且给容器提供了太多特权。 You can try running the container with --cap-add SYS_ADMIN in stead. 您可以尝试使用--cap-add SYS_ADMIN代替来运行容器。

Alternative solution 替代解决方案

A much cleaner solution could be to mount hugepages on the host , and give the container access to that device, eg; 一个更干净的解决方案可能是在主机上挂载大量页面 ,并允许容器访问该设备。

docker run --device=/dev/hugepages:/dev/hugepages ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM