Skip to content

Instantly share code, notes, and snippets.

@lnksz
Last active June 27, 2024 08:26
Show Gist options
  • Save lnksz/a6519f49aec2397259bfd8bcd1cf3925 to your computer and use it in GitHub Desktop.
Save lnksz/a6519f49aec2397259bfd8bcd1cf3925 to your computer and use it in GitHub Desktop.
Add host user alter ego in tmp docker container

E.g. in a docker container which is mapped into host via volumes, but has root user only Start tmp container with linked in current folder

id
docker run -it --rm -v "$PWD":"$PWD" -w "$PWD" ubuntu /bin/bash

In container add user with the id which is present on host as well, e.g. builder:builder with 1001:1001 if uid is defined, the user-group GID will be the same

# useradd --create-home --user-group -u 1001 -G sudo --shell /bin/bash builder
# su builder
$ id

Useful e.g. with building buildroot in a container, because buildroot doesn't want to build as root Also the built artifacts then do not need to be chown-ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment