简体   繁体   中英

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.

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?

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 ); 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

Second, doing mount in a container requires additional privileges. You can use --privileged but that is probably far too wide of a step, and gives far too much privileges to the container. You can try running the container with --cap-add SYS_ADMIN in stead.

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 ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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