TIL: How to run Docker in rootless mode
Feb 4, 2025. 228 words. 2 minutes. In TIL. Docker System Linux
tl;dr:Running Docker without sudo is pretty easy and just requires two lines in the shell.
For a long time I thought that it was best practice to run Docker in root mode,
i.e., running all commands with sudo. As this can get annoying very quickly
(as is so often the case with security practices…), I read a lot of guides
how to circumvent this, often involving insecure practices like messing with
the sudo group. So in the name of (perceived?) security, I never bothered
much with it and just typed my sudo in front of every command.
As I was collaborating on a shared project with a colleague, the issue arose
again, as he had a setup without the need for calling Docker with sudo. So I
researched the topic again and there is actually an official guide from Docker
for this with a clean solution 1. It boils down to these two lines:
| |
Afterwards, any image needs to be rebuilt and each container needs to be restarted,
as the rootless Docker runs in its own domain, so sudo docker ps and docker ps actually would return different results.
There are some caveats and limitations that the documentation describes, but nothing that affects me (so far). Your mileage may vary!
References #
Other posts related to this one: