5

Transparent Huge Pages is required to be disabled for the TokuDB engine and for Redis. With docker-toolbox, I could just docker-machine ssh into the host and disable it. I no longer have access to the host OS, so how do I disable it?

chicks
  • 2,393
  • 3
  • 24
  • 40
Root Fool
  • 324
  • 2
  • 11

2 Answers2

3

You can actually do this with a privileged container in Docker For Mac/Windows. You can do it like this:

docker run -ti --privileged ubuntu /bin/bash
echo never | tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | tee /sys/kernel/mm/transparent_hugepage/defrag

I ended up creating an image for this and made redis/mariadb include it under depends_on in my docker-compose.yml file

FROM ubuntu:latest
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

where docker-entrypoint.sh has:

#!/bin/bash
set -e

echo never | tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | tee /sys/kernel/mm/transparent_hugepage/defrag
Root Fool
  • 324
  • 2
  • 11
  • 1
    Running a container as privileged allows the container to access the host and isn't generally a good idea for security reasons. There is a post here about how to log into the VM in Docker for Mac, but it seems a bit of a hack: https://forums.docker.com/t/docker-for-mac-how-to-set-host-settings-sysctl-etc/11168 I'm not aware of an official way of doing this yet. – foz Mar 07 '17 at 10:05
  • What is the advantage (if any) of using the `echo ... | tee ` pattern over simply `echo ... > ` ? – cueedee Aug 15 '23 at 08:26
2

An even easier solution is to create file profile with content

echo never > /sys/kernel/mm/transparent_hugepage/enabled 
echo never > /sys/kernel/mm/transparent_hugepage/defrag

and add following line to Dockerfile

COPY profile /var/lib/boot2docker/profile
Coolius
  • 53
  • 1
  • 6