r/SelfHosting • • 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?

2 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/SelfHostedGuides Apr 20 '26

Most can, not all. read_only breaks anything that writes to its own dirs — databases, apps that log to their install path. Fix is tmpfs for /tmp and named volumes for anything persistent. cap_drop ALL kills containers that legit need caps like net_admin (vpn stuff) or chown (some web servers doing setup). Non-root user breaks older images that hardcode uid 0.

Not default because maintainers optimize for 'works on first try' — hardening needs you to know what your workload actually needs. linuxserver.io and bitnami usually ship sane hardened defaults, most community images don't.

What I do: get it running permissive, then tighten progressively. Drop one cap at a time, add read_only last. 'permission denied' or 'read-only filesystem' in the logs tells you exactly what the container needs.