Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 206
Amit Singh Tomar Avatar asked Jan 14 '16 10:01

Amit Singh Tomar


People also ask

Can you use localhost in docker?

Alternatively you can run a docker container with network settings set to host . Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0.0.1 ) will refer to the docker host.

What are huge pages Kubernetes?

HugePages configuration allows a Pod to access memory pages larger than the Linux kernel's default memory page size, which is usually 4 KB. Many memory-intensive applications, like Elasticsearch and Cassandra, take advantage of using huge pages.


1 Answers

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

Alternative solution

A much cleaner solution could be to mount hugepages on the host, and give the container access to that device, e.g.;

docker run --device=/dev/hugepages:/dev/hugepages ....
like image 143
thaJeztah Avatar answered Sep 22 '22 14:09

thaJeztah