Setting sysctl in Dockerfile.template


#1

Hello,
I create an Dockerfile.template for redis and I want to set the command:
RUN sysctl vm.overcommit_memory=1
But I can’t do this, I got an:

Build failed: The command '/bin/sh -c sysctl vm.overcommit_memory=1' returned a non-zero code: 255
How can I set the sysctl before the redis-server starts?


#2

Hey @Tom71, Welcome to resin.io :slight_smile:

So the problem you are hitting there is that everything in the Dockerfile is being run on our build server in the cloud and not actually on your target device, so sysctl can’t actually make calls to the kernel there (even if it could, it wouldn’t help much). So I believe what you need to do is add something like:
CMD sysctl vm.overcommit_memory=1 && redis-server

CMD is the first thing that runs as the container starts on your device, so this will run sysctl and then launch redis server.


#3

This works fine. Thank you