Search code examples
dockerpermissionsrootmambamicromamba

Directory Ownership in Container: root vs mambauser


We're attempting to move one of our images from using miniconda3 as the base image to micromamba (1.5-bookworm-slim).

Our repository contains a Makefile that has commands to build the image and run a few tests.

The build is nothing special, and so is the Dockerfile. (We briefly switch to root to install a package using APT. The default user within the micromamba image is mambauser.)

The test command is as follows:

docker run --mount type=bind,source="$$(pwd)/test-data",target=/assets --mount type=bind,source="$$(pwd)/test-output",target="/tmp/test-output"  image_name:tag [call to script and arguments omitted]

This eventually fails on my Ubuntu system because the script is not able to write to the /tmp/test-output directory because it is owned by root. However when a colleague runs it on his Mac, the owner of the folder is mambauser and the test runs successfully.

When I explicitly add --user mambauser to the run command, the owner shows up as 1000, but the test still fails.

Short of setting the user to root in the Dockerfile or running the test as root, is there a way to get this to work?

Happy to share relevant details of Dockerfile, system settings etc., if required.


Solution

  • Passing the user and group ID (or name) of the current user as an argument to the docker run command resolved the issue.

    docker run -u "$(id -u):$(id -g)"

    Refer: https://github.com/mamba-org/micromamba-docker/discussions/382#discussioncomment-7495825