I'm learning Podman so I apologize for silly mistakes.
Docker Redis has a notorious problem where the database might fail to write if in the container /proc/sys/vm/overcommit_memory
is not set to 1 (the default value is 0).
I know that Podman doesn't use a Daemon and I thought that this could allow it to set specific host environmental values per container (Docker doesn't allow this -- one must change the host variables and then all containers being created will copy them; thus, if you set a different value for the host environmental variables it will be applied to all subsequent containers, there's no way to apply it only to a specific one).
The documentation says that, for --env
, "--env: Any environment variables specified will override previous settings". But alas, I think it behaves identically to Docker and doesn't allow one to change host env per container. I tried podman run .... --env 'overcommit_memory=1'
and it made no difference at all. I guess this approach would only make sense for general environmental variables and not for specific vm
ones.
But I was curious: is it possible at all to change host env per container in Podman? And in specific, is there any way to change /proc/sys/vm/overcommit_memory
per container?
EDIT: can podman play kube
be of any help?
EDIT2: one might wonder why I don't encapsulate the podman run
command with echo 1 > overcommit_memory
and afterwards revert to echo 0 > overcommit_memory
, but I need to use a Windows machine to develop this and I think this wouldn't be possible
EDIT 3: Eureka! Found a solution [not really, see criztovyl's answer] to my original problem, I just need create a dir (say, mkdir vm
), add a overcommit_memory
file to it with content equal to 1
, and add to the podman run
instruction -v vm:/proc/sys/vm:rw
. This way a volume is bound to the container in rw
mode and rewrites the value of overcommit_memory
. But I'm still curious as to whether there's a more straightforward way to change that env
EDIT 4: Actually, COPY init.sh
is the best option so far https://r-future.github.io/post/how-to-fix-redis-warnings-with-docker/ [again, not really, see criztovyl's answer below]
As Richard says, it does not seem to be currently possible to set vm.overcommit_memory
per-container, you must set it at the host via sysctl
(not --sysctl
).
This applies to both Podman and Docker, as for the "actual" container they both in the end rely on the same kernel APIs (cgroups).
Note that you say "changing the host env", which can be misinterpreted as changing the host's environment variables. Overwriting environment variables is possible as you tried with --env
.
But memory overcommit is a kernel parameter which you must set via sysctl
, not environment variables.
Certain sysctl options are overwriteable via --sysctl
, but vm.overcommit_memory
is, as far as i can tell, no such option.
Regarding your first edit: kube play
only is a fancy way to "import" pods/containers described in kubernetes yaml format. in the end it does not set different options you could not also use manually.
Regarding your second edit: I dont think for development you need to toggle it, it should be okay to just keep it enabled. Or keep it disabled altogether because during development the warning and potential failing writes should be acceptable.
Your option 3 only silences the warning, but the database write can still fail, it only makes it appear to redis overcomitting is enabled, but actually overcommit is still disabled.
Your option 4 works with a privileged container, enabling overcommit for the whole host. As such it is a convenience option for when you can run privileged containers (eg during development), but it will fail when you cannot run privileged (eg in production).