# Day 6: Docker Update Permissions
🎯 Objective
Allow the existing user rose on App Server 2 to run Docker commands without using sudo.
Normally, Docker commands require root privileges:
sudo docker psThe goal is to allow:
docker pswithout sudo.
🧠 Concept
Docker uses a Unix socket to communicate with the Docker daemon:
/var/run/docker.sockThis socket is normally owned by:
root:dockerUsers who belong to the docker group can access this socket and communicate with the Docker daemon without using sudo.
The permission flow is:
rose
↓
Add to docker group
↓
docker group has access to /var/run/docker.sock
↓
Docker daemon
↓
Run docker commands without sudo🔍 Step 1: Check the User
Verify that rose exists and check the current group membership:
id roseOutput:
uid=1001(rose) gid=1001(rose) groups=1001(rose)This confirms that:
🐳 Step 2: Check the Docker Group
Check whether the docker group exists:
getent group dockerOutput:
docker:x:992:steveThis tells us:
Group Name → docker
Group ID → 992
Member → steveAt this point, rose is not a member.
🔐 Step 3: Check Docker Socket Permissions
Check the Docker daemon socket:
ls -l /var/run/docker.sockOutput:
srw-rw---- 1 root docker 0 Aug 9 14:31 /var/run/docker.sockUnderstanding the Output
srw-rw---- 1 root docker ...
│ │ │ │
│ │ │ └── Group: docker
│ │ └─────── Owner: root
│ └───────── Socket metadata
└──────────────────── PermissionsThe permissions are:
srw-rw----Breaking them down:
s → Unix socket
rw- → Owner (root) can read/write
rw- → Group (docker) can read/write
--- → Others have no permissionThe important part is:
root dockerTherefore, a user who belongs to the docker group can communicate with the Docker daemon through this socket.
> /var/run/docker.sock is not a command or executable file. It is a Unix socket used for communication between the Docker CLI and Docker daemon.
👤 Step 4: Add rose to the Docker Group
Add rose to the existing Docker group:
sudo usermod -aG docker roseCommand Breakdown
usermodModifies an existing Linux user.
-aAppend the user to additional groups.
-G dockerAdd the user to the docker supplementary group.
roseThe user being modified.
⚠️ Why aG Matters
Use:
sudo usermod -aG docker roseinstead of:
sudo usermod -G docker roseWithout -a, existing supplementary group memberships could be replaced.
-a → Append
-G → Supplementary GroupsTherefore:
sudo usermod -aG docker roseis the safe command.
🔍 Step 5: Verify Group Membership
Check rose again:
id roseOutput:
uid=1001(rose) gid=1001(rose) groups=1001(rose),992(docker)Now we can see:
992(docker)This confirms that rose has successfully been added to the Docker group.
Before
uid=1001(rose) gid=1001(rose) groups=1001(rose)After
uid=1001(rose) gid=1001(rose) groups=1001(rose),992(docker)The change is:
rose
├── 1001(rose)
└── 992(docker) ✅🔄 Session Note
Linux determines supplementary group membership when a login session starts.
If rose already has an active session, that existing session may not immediately recognize the new docker group membership.
A new login session will normally pick up the updated group membership.
The configuration itself can be verified with:
id rosewhich now shows:
992(docker)⚙️ Complete Commands
Check User
id roseOutput:
uid=1001(rose) gid=1001(rose) groups=1001(rose)Check Docker Group
getent group dockerOutput:
docker:x:992:steveCheck Docker Socket
ls -l /var/run/docker.sockOutput:
srw-rw---- 1 root docker 0 Aug 9 14:31 /var/run/docker.sockAdd User to Docker Group
sudo usermod -aG docker roseVerify
id roseOutput:
uid=1001(rose) gid=1001(rose) groups=1001(rose),992(docker)🔐 Security Note
Membership in the docker group provides powerful access to the system.
A Docker user can potentially:
Therefore, only trusted users should be added to the docker group.
🧪 Validation Checklist
📌 Summary
The Docker socket permissions are:
ls -l /var/run/docker.socksrw-rw---- 1 root docker 0 Aug 9 14:31 /var/run/docker.sockThis means the docker group has read/write access to the Docker socket.
Initially:
id rosereturned:
uid=1001(rose) gid=1001(rose) groups=1001(rose)Add rose to the Docker group:
sudo usermod -aG docker roseVerify:
id roseResult:
uid=1001(rose) gid=1001(rose) groups=1001(rose),992(docker)The complete permission relationship is:
rose
│
│ member of
▼
docker group (GID 992)
│
│ rw permission
▼
/var/run/docker.sock
│
│ communication
▼
Docker daemonThe key takeaway is:
> /var/run/docker.sock is a Unix socket, not something we execute. Because the socket belongs to the dockergroup with read/write permissions, adding rose to that group allows the user to communicate with the Docker daemon without sudo.