Files created by dockerized commands are not owned by the host's current user, but for example root.
This makes dockerized hard to use on unix systems, as generated files cannot be modified by the user.
It is also inconsistent with the design goal that Dockerized commands should behave the same as native commands.
These are all ideas I could come up with so far. Your thoughts and suggestions are welcome.
The goal is to find a solution with no blockers (:x:), and remove ❔ by doing more research.
Run the docker image with the uid/gid of the host system
❔ Ensure container images still work
:x: The host's user id will not exist in the container. This leads to several problems:
Container files owned by root (which is the default on most images) may become inaccessible, e.g. /root
The user will not have a username
The user will not have a home directory (~ will point to /)
❔ Create a user inside the docker container with the host uid/gid, upon start (i.e. with an entrypoint)
❔ Might clash if the specific container already uses that user-id.
❔ Create a dockerfile for each app, that creates a host user, baked into the image
❔ How to ensure this works for multiple host users? E.g. if the host switches to user2, dockerized should still work, and create files as user2.
❔ Map host ids to container ids
userns-remap
Requires re-configuring docker, and is global.
❔ Will this impact the user's other containers? If so, this is not a great option.
ID translation
❔ Does this exist somehow? Docker doesn't seem to allow ad-hoc uid translation.
✔/:x: Changing the owners/permissions of the generated files after each command is run
:x: This won't work for long running commands, such as npm run which continuously updates files. Permissions won't be fixed until the program finishes.
Detecting which files need permission fixes:
:x: Cannot use file stats, as some commands output files with specific mtimes (e.g. tar)
:x: Cannot rely on just detecting new files, as some files may have been re-created with different owners
✔️ Remembering all files + permissions before the command, and detecting new files and files with different owners/permissions.
Description
Files created by
dockerized
commands are not owned by the host's current user, but for exampleroot
. This makes dockerized hard to use on unix systems, as generated files cannot be modified by the user.It is also inconsistent with the design goal that Dockerized commands should behave the same as native commands.
Reproduction
Possible Solutions
These are all ideas I could come up with so far. Your thoughts and suggestions are welcome. The goal is to find a solution with no blockers (:x:), and remove ❔ by doing more research.
root
(which is the default on most images) may become inaccessible, e.g./root
~
will point to/
)/root
npm run
which continuously updates files. Permissions won't be fixed until the program finishes.docker
fix the permissions. I.e. rundockerized alpine chown $(id -u):$(id -g) $FILES
(this works)docker
or another user.