docker rootles: mkdir /var/lib/docker/network: permission denied
- User
docker rootles: mkdir /var/lib/docker/network: permission denied
Assistant
This error
mkdir /var/lib/docker/network: permission deniedwhen running Docker in rootless mode is a strong indicator of a misconfiguration or misunderstanding of how rootless Docker works.Why this happens:
Rootless Docker does not use
/var/lib/dockerfor its data directory. That path is reserved for the traditional, root-privileged Docker daemon.When you run Docker in rootless mode, its data is stored in your user's home directory, typically at
~/.local/share/docker(or~/.dockerin older setups).The error means that your Docker client (or possibly the rootless daemon itself) is trying to operate on the standard
/var/lib/dockerpath, which your non-root user doesn't have permission to write to.Most Likely Causes and Solutions:
-
DOCKER_HOSTEnvironment Variable is Pointing to the Wrong Socket: This is by far the most common cause. Your client might be trying to connect to the system-wide (rootful) Docker daemon's socket, instead of your user-specific (rootless) daemon's socket.- Check it:
echo $DOCKER_HOST - Expected for Rootless: It should either be unset (so it defaults to the rootless socket) or explicitly set to something like
unix:///run/user/$(id -u)/docker.sock. - Problematic: If it's
unix:///var/run/docker.sockor empty while a rootful daemon is running, your client will try to talk to the rootful daemon. - Solution:
Then try your Docker command again. Whenunset DOCKER_HOSTDOCKER_HOSTis unset, Docker will look for the default rootless socket if a rootless daemon is running, or the default rootful socket if not.
- Check it:
-
Rootless Docker Daemon is Not Running or Not Configured Correctly: Even if your
DOCKER_HOSTis correct, the rootless daemon itself might not be running.- Check if it's running (using systemd user service):
It should show assystemctl --user status dockeractive (running). If not, start it:systemctl --user start docker systemctl --user enable docker # To start on login - Verify Rootless Status:
It should outputdocker info | grep "Rootless"Rootless: true. If it'sfalseor the command fails, your setup isn't properly rootless.
- Check if it's running (using systemd user service):
-
Conflicting Rootful Docker Daemon: If you also have a traditional root-privileged Docker daemon running alongside your rootless setup, and your
DOCKER_HOSTis accidentally pointing to it, then you'll get this error.- Check if a rootful daemon is running:
sudo systemctl status docker - Action: If you intend to only use rootless Docker, consider disabling or stopping the rootful one to avoid confusion. If you need both, always ensure your
DOCKER_HOSTpoints to the correct one for the tasks you're performing.
- Check if a rootful daemon is running:
-
Incomplete or Incorrect Rootless Installation: If you didn't follow the official rootless installation steps (e.g., using
dockerd-rootless-setuptool.sh), your environment might not be set up correctly.- Review the official guide: Refer to the Docker documentation for "Run the Docker daemon as a non-root user (Rootless mode)". The
dockerd-rootless-setuptool.shscript usually handles setting up theDOCKER_HOSTfor your session and configuring thesystemd --userunit.
- Review the official guide: Refer to the Docker documentation for "Run the Docker daemon as a non-root user (Rootless mode)". The
Troubleshooting Steps (in order):
-
unset DOCKER_HOST: This is the quickest and most common fix.unset DOCKER_HOST docker run hello-world # Test it -
Verify Rootless Daemon Status:
systemctl --user status dockerIf not running, start it:
systemctl --user start docker -
Check
docker info:docker info | grep "Rootless" docker info | grep "Docker Root Dir"Rootless: trueis good.Docker Root Dirshould be in your home directory (e.g.,/home/youruser/.local/share/docker). If it's/var/lib/docker, something is deeply wrong with your rootless setup. -
Restart your terminal session or log out/in: Sometimes environment variables from previous sessions or system-wide configurations can persist. A fresh session ensures a clean environment.
By following these steps, you should be able to resolve the "permission denied" error and get your rootless Docker setup working correctly.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.