docker / docker/cli

Feature request: CLI flag for running container as the current user

Open
#3,498 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/enhancement
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

There are many use cases where Docker containers are used as development environments to bundle dependencies and provide consistent development experience. Docker daemon uses such an approach as well). In order to allow developers to modify the files in the IDE outside the container, the project’s working directory is often mounted inside the container like this:

$ docker run -v $(pwd):/mount my_container /bin/bash

However, this creates a problem where all the files, created by the process inside the container, are owned by this process’ user, which is often root. Removing root-owned files from the project directory requires juggling sudo commands around and is tedious in general.

Often it’s not even necessary to run the containerized process as root at all, and the following command can be executed to run it as the current user:

$ docker run --user $(id -u):$(id -g) -v $(pwd):/mount my_container /bin/bash

However, this is cumbersome to type in the terminal and bloats the scripts in which it’s used. It would be neat to have a dedicated boolean flag, for instance --current-user, which would fetch the current user’s UID and GID (using Go’s standard library) and use them for running the container’s process.

This would shorten the above example to:

$ docker run --current-user -v $(pwd):/mount my_container /bin/bash

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the docker run CLI option handling, then review Go's os/user package as referenced in the issue. Check how the existing --user value is passed to the container process and determine the platform behavior that must be covered. Done means --current-user runs the process with the invoking user's UID and GID, matching the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.