Is there a way to run a docker container as sudo, if it was build on a non sudo base-image? Is there a way to run a docker container as sudo, if it was build on a non sudo base-image? docker docker

Is there a way to run a docker container as sudo, if it was build on a non sudo base-image?


with docker run you can pass the user flag.

-u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])

I believe the UID of root should be 0, so I think any of -u root -u 0 -u root:root should work?

If you're building a Dockerfile you can also add USER root to your dockerfile to switch users.


A quick workaround that also worked was to use a multi-stage build, start off as sudo in the first build, do RUN sudo chmod +s /usr/bin/gdb and then use COPY in the second stage to get gdb with permissions from the first stage.