DockerJunior

Docker commands only work with sudo

On Linux the Docker socket belongs to root and the docker group. Add your user to the group, or use rootless mode, and mind the security cost.

What you see

  • docker works with sudo but fails without it
  • After adding yourself to the group: WARNING: Error loading config file: /home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied

What it means

The Docker daemon listens on a Unix socket that root owns. Other users can only use it through sudo, unless they are in the docker group, because the daemon creates the socket so members of that group can reach it.

Be clear about the cost. The docs warn that the docker group grants root-level privileges to the user.

How to confirm the cause

  1. 1
    See which groups you are in
    id

    Look for docker in the list. Group changes only apply to new login sessions.

Causes and fixes

  • Your user is not in the docker group

    HOW TO TELL
    id does not list docker.
    FIX
    Create the group if it does not exist, add your user, then log out and back in. In a VM you may need to restart it. You can also run newgrp docker to pick up the change in the current shell.
    sudo groupadd docker
    sudo usermod -aG docker $USER
    newgrp docker
    docker run hello-world
  • ~/.docker has the wrong owner after running docker with sudo

    HOW TO TELL
    The config.json permission denied warning above.
    FIX
    Remove ~/.docker/ (it is recreated, but custom settings are lost), or fix its owner and permissions.
    sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
    sudo chmod g+rwx "$HOME/.docker" -R

How to stop it coming back

  • Run Docker as a non-root user with rootless mode if the root-level access of the docker group is not acceptable in your environment.
  • Do not mix sudo docker and plain docker on the same machine.

Keep going

Sources

Docker documentation (docs.docker.com), read 18 Nov 2026 from the official docs repository.

Search

Search cheat sheets and projects