New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI flag for running container as the current user #3499
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Konrad Ponichtera <konpon96@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #3499 +/- ##
=======================================
Coverage 59.01% 59.02%
=======================================
Files 284 284
Lines 23833 23846 +13
=======================================
+ Hits 14066 14076 +10
- Misses 8908 8910 +2
- Partials 859 860 +1 |
I have modified the code and implemented the suggestion, mentioned in #3498. Instead of new |
Please see the recent discussion in #3498 (comment) |
I think, yes. |
dea9b89
to
f023b2d
Compare
Closes #3498
- What I did
I’ve added the
--current-user
boolean flag to thedocker run
command to avoiddocker run -u $(id -u):$(id -g)
construct which often appears in the scripts that use Docker containers for development.- How I did it
The user parameter of the Docker API call is now built by the dedicated
parseUser
function inopts.go
file. It checks if--current-user
flag was set. In such case, it fetches current user UID and GID using Go’s standard library, builds the stringUID:GID
, and passes it to the Docker API. The--user
flag has precedence over--current-user
- if both are specified, the--user
one will be taken.There is also a unit test, which verifies the behavior of the function that builds the API call user field. I’ve also updated bash and zsh autocompletion files, as well as the Markdown reference document for the
run
command.If there are some things that should be done and which I missed, please let me know and I will address them.
- How to verify it
docker buildx bake
./build/docker run -it --current-user ubuntu /bin/bash
- the Ubuntu container will run the process inside with the same UID and GID as the CLI caller’s process../build/docker run -it --current-user -u 1234:1234 ubuntu /bin/bash
- the-u
flag will take precedence- Description for the changelog
Added
--current-user
flag to thedocker run
command.- A picture of a cute animal (not mandatory but encouraged)