I'm ssh'ed into a local Centos 7 docker container* and I'm trying to run
sudo chattr +i file1
but I'm getting an error:
chattr: Operation not permitted while setting flags on file1
What's going on here? What flags is it talking about? Is there a workaround?
Changing the +i
to +a
also makes the command fail with that error, but when I change it to +d
the command succeeds. The command also succeeds for me when I'm not ssh'ed into a docker container.
*I'm running the Centos 7 docker container in a Ubuntu VirtualBox VM host on top of Windows 10 (I'd like to avoid having to deal with Windows as much as possible). The ultimate goal of all of this is to test some Ansible scripts using these containers.
Best Answer
This is related to capabilities thing:
chattr
requiresCAP_LINUX_IMMUTABLE
which is disabled in docker by default. Just add--cap-add LINUX_IMMUTABLE
to docker container start options to enable it.Here's an example:
Here you can read more about linux capabilities in docker.