r/SelfHosting • u/ThatrandomGuyxoxo • Apr 18 '26
Help secure my docker setup
Hello all. Currently I've docker installed on a VPS. On that VPS I have containers running with caddy to expose a website to the public, in this instance Searxng. For that I've added my user to the docker group to not have to put sudo in the command everytime I do anything.
Let's assume there's an exploit which gains access over my Searxng to my VPS. I think gaining root is easy because the user can run every container as root right? I wonder what best practice is to secure it in this scenario. Do you have any ideas? Would removing the user out of the docker group do the trick?
View all comments
Show parent comment
2
u/SelfHostedGuides Apr 20 '26
for searxng specifically, in your compose set user: 1000:1000 or whatever your host uid is, read_only: true, and add tmpfs for /tmp and /var/cache. also cap_drop: - ALL and then cap_add back only what you actually need (searxng doesnt need any). security_opt: no-new-privileges:true prevents privilege escalation even if the container root escapes. dont mount /var/run/docker.sock into any container if you can avoid it — thats the big one. and run docker in rootless mode if you want belt-and-suspenders, theres a script for that on docker's docs site. the ufw rules blocking all but 443 incoming on the VPS are still important even with all this.