Skip to main content

Command Palette

Search for a command to run...

How to Fix "User Not in Sudoers File" Error in Docker Containers

How to resolve 'user not in sudoers file' error in a Docker container from outside

Updated
1 min read
How to Fix "User Not in Sudoers File" Error in Docker Containers

The Problem

Earlier today, I was exploring dev containers from Microsoft and trying to set up a Rust dev container using Distrobox on Docker. I got stuck at the 'user not in sudoers file' error. The typical solution is to add the user to the sudo group using:

usermod -aG sudo $USER

The problem with this command is that I had to be a member of the sudo group, but I wasn't. Later, I tried:

su

for which, again, I had to know the root password. This was still an unknown. At this point, I was thinking of other solutions until...

The Solution

I remembered that Docker has an exec command that allows executing commands as the root user on containers. Then I tried:

docker exec -it <container_name or container_id> sudo usermod -aG sudo $USER

for example in my case it was the rustbox container,

docker exec -it rustbox sudo usermod -aG sudo $USER

If this solution helped you, then leave a like or comment for anything I may be missing. Happy to help, happy coding! 🖥️

More from this blog