r/docker • • 5d ago

Docker root question

I am a networking novice and I am using AI (claude) to guide me through installing and testing Immich on a homelab server (ubuntu 26.04) We are discussing the setup and one of the things immich needs is docker. The ai is telling me that docker needs to run its service as root (by default.) it says it can be run as a non-root user, but that requires different packages and more setup.

I just wanted to touch base with reality here since I am working with an AI. Claude has been fairly realistic about the risks, i.e. that the main risk would be if there is ever a mistake in the docker code or if something is misconfigured an attacker could gain root access, which could happen to any program running as root. I don't think the AI is being overly pessimistic, but I just wanted to see what some actual humans think ... and hopefully they won't just use an AI to respond :)

Does it make sense to try and run docker as a non-root user? what are the realistic risks here? Nothing is installed yet and there is no particular hurry, this is just a test project.

Thanks very much!

7 Upvotes

16 comments sorted by

6

u/theblindness Mod 5d ago

Since you are new to docker and this is only for homelab, follow the official docs, start with the simplest setup first, get it working that way, and then you can circle back to evaluate your threat model and optimize for it.

Docker as root is the default way it operates. If this is your homelab and you are the only user sharing the system, many of the issues that rootless addresses are either hypothetical or entirely not relevant to you. If you run into one of those issues later, you can switch to rootless.

AI models will be influenced by all of the noise online, and often won’t follow the guidance on the latest version of the official docs. You can ask Claude to explain things in the docs to you, but the latest update of the official docs should be your source of truth, not a regurgitation of everything found on the web.

Optimizing first, before you have a baseline, especially while you are still early in learning, may be premature.

1

u/Hansehart 5d ago

Regular rootful Docker is fine and it's the standard setup. Rootless works too, but it adds friction you don't need for a test project. The two things that actually bite: anyone in the docker group is effectively root, and ports you publish in compose skip ufw entirely, so bind them to your LAN IP or 127.0.0.1 instead of exposing them to everything. If you ever want rootless without the extra setup, Podman runs that way by default. However I personally use rootless docker too.

1

u/pookshuman 5d ago

This would be my first time using docker so I don't really understand this. What should I take away from this? As a first time user, what should I do? root docker or rootless?

2

u/Hansehart 5d ago

Most people run docker with root. So its fine if you do too. Make sure to not expose any ports you dont want to, configure a proper firewall and keep your sytems up2date. Thats it.

1

u/CrownstrikeIntern 5d ago

The setup is not that bad and you should get in the habit of building rootless containers. If someone does a container break they can do a lot on your machine. Even for development, get in the habit, as good habits make good practice because you don't want a root install on production and you want your volumes as locked down as possible.

1

u/pookshuman 5d ago

ok, so your vote is for rootless?

1

u/CrownstrikeIntern 5d ago

I do it for my dev and prod setups. My dev mirrors my prod so there's no guessing. And yes, rootless. If someone does a container break out, They get root access to your machine, and then you're screwed. I wanted some demos on how easy that was for some people so why chance it. All my important things are also encrypted as rest, everything is role based access list protected. And a handful of other protections. And once you got that mastered, it's pretty easy. Its a learning curve in the beginning like you may have to enable some ip forwarding flags on the hosts and setup some port translations if you want to use standard ports Example 443, without allowing it on the compose file.

2

u/xpery_mint 5d ago

Edit: bad autocorrect

First of all I’m just a guy with a homelab. No IT Professional. So my answer should be weighted accordingly.

TLDR: Depends on what you are planning to do. For me it was not worth the effort.

I used docker rootless myself for some time. I wanted to have my services on the web via reverse proxy and authelia and whatnot.
Setup isn’t that hard. There’s a manual at the docker website.
But the problems started with a pi hole. Port 53 is privileged.
Some playing around and it works. Next container just works in host mode.
Some playing around and it works.
Server sits around for 3 months due to lack of time.
WHAT THE HELL DOES THIS SERVER DO?
So back to normal docker and I put everything under the hood of Tailscale. No ports to the internet. For my risk profile and user profile that’s fine.

1

u/Open-Adhesiveness-86 5d ago

Rootful is fine for a test box, but if you do go rootless, two things nobody warns you about: you need loginctl enable-linger $USER or your containers get killed the moment you log out of SSH, and anything under 1024 won't bind unless you lower net.ipv4.ip_unprivileged_port_start. Immich-specific, hardware transcoding via /dev/dri is also more annoying rootless since the uid mapping has to line up with the render group. I'd just run rootful, keep your compose files owned by your normal user, and bind published ports to the LAN IP.

1

u/NoDevelopment206 5d ago

for a first test install i'd just use regular docker and not spend time on rootless. the setup that matters more is how you expose Immich. keep it on your LAN or behind a VPN like Tailscale instead of forwarding ports to the internet, and don't add extra users to the docker group. also back up the Immich database and photo folder before upgrades, since that is the part you'd actually hate to lose. if the project turns into something permanent, you can look at rootless or Podman later.

1

u/Xia_Nightshade 5d ago

I run docker rootless in my homelab atm, it’s great, but

Quite some extra config, which is very hard if you can’t grasp the basics.

Run it as root. Learn things, get things runnning. Learn about securing Linux (fail2ban, firewalls,…)

It doesn’t have to be perfect. Once you feel comfortable with what you are doing, have a look at rootless.

You could be: enjoying your self hosted app, learning a ton along the way, or; figure out all rootless stuff.
I would start with the first, knowing rootless exists and is better is a good lesson here. Let it be for now, don’t kill the fun ^^

1

u/zoredache 4d ago edited 4d ago

it says it can be run as a non-root user, but that requires different packages and more setup.

Depends on what your goal here is. With the standard docker daemon, you can have the containers run in an isolated user namespace. Meaning the containers will not have root access, but the daemon itself would still have root access. This is an option the docker daemon had for a lot longer then the existence of the rootless daemon.

Using the userns-remap feature gives you some of the similar protections you get from the rootless mode. It cuts down on a lot of the potential risk from running containers without having to run the rootless docker daemon.

The setup isn't particularly difficult, just requires another option in your daemon.json.

If you are going to use this option you should set it before you create any containers, volumes, or images on the system, since it will impact the permissions of all those things. You shouldn't try to change the userns-remap after it has been enabled, or you'll have a complicates mess with your filesystem permissions.

https://docs.docker.com/engine/security/userns-remap/

There is some limitations with doing the rootless docker daemon usernms remap feature. It should be obvious, won't be able to use any 'privileged' containers. You will have to do some complicated work, if you want to access the container data directly, outside of the container.

Does it make sense to try and run docker as a non-root user?

If you can run with userns-remap, or the rootless docker daemon it would be a pretty good idea to do so. Additional layers of security are often a good thing.

If you only plan on running Immich, I believe that should be perfectly fine running with the userns-remap, or the rootless docker daemon.

1

u/Hostman_com 4d ago

Regular Docker is a reasonable starting point for a first Immich install on a single-user homelab. Its daemon runs as root, so treat the `docker` group and access to its socket as admin access. Keep that socket out of the Immich containers.

If you're indexing an existing photo library, mount it read-only. Immich's upload directory still needs to be writable.

1

u/lxtakc 4d ago

For a test Immich box, default rootful Docker is fine. The real catch is that anyone in the docker group is effectively root, so only add accounts you trust, and don't mount the Docker socket into containers. Rootless is worth trying later if this becomes something you expose or keep long term.

1

u/xanyook 3d ago

Do you expose your service on the internet or just your local network ?

-1

u/Only-Stable3973 5d ago

I don't use sudo when creating or editing my compose files, keeping these configuration files owned by standard user prevents permissions headaches. Make sure you are added to the docker group, sudo usermod -aG docker $USER