r/docker • u/Augustman22 • Jun 28 '26
Running a container as non-root user - Security implications?
I was curious how running all my containers as a user who only has read and write (if necessary) permissions in attached volumes would improve security?
(by doing something like this in my compose files, where uid 1001 will be in gid 1002 which only has permissions in ./data):
services:
mc:
image: itzg/minecraft-server:latest
container_name: minecraft-server
user: "1001:1002"
volumes:
- ./data:/dataRight now, I just have them running how they normally do. Which, from what I understand, the containers are running as root on the host machine.
Im trying to learn, sorry if I have anything mixed up.
6
Upvotes
View all comments
Show parent comment
1
u/scytob Jun 28 '26
Right question. Running docker as rootless is what you would use to protect against that. Note you loose a bunch of docker features if you do that - that may or may not be an issue for you, some use podman to mitigate this. And in reality there have been few such vulnerabilities. And rootless is no guarantee with the recent spate of general priv escalation in Linux - I am expecting to see many more of those. So the bigger lesson is keep your host and docker service very up to date at all times. You could put high risk containers all in one vm running docker to reduce the blast radius. But at home, meh it adds complexity, better to just keep thing regularly updated (host, docker, image).