testcontainers-node icon indicating copy to clipboard operation
testcontainers-node copied to clipboard

Support copying files to a container with a given ownership

Open cristianrgreco opened this issue 2 years ago • 4 comments

The Docker API for copying an archive to a container has a flag CopyUIDGID.

You could therefore chown a file locally to whatever UID/GID required, and this ownership will be retained in the container. This simulates an equivalent of

COPY --chown=user:group myfile /path/in/container/myfile

# OR

COPY myfile /path/in/container/myfile
RUN chown user:group myfile

cristianrgreco avatar Jul 13 '23 10:07 cristianrgreco

@mutantcornholio Would something like this work for your use case? Specifically setting the UID/GID on the file locally to the desired UID/GID on the container?

cristianrgreco avatar Jul 13 '23 10:07 cristianrgreco

Totally!

mutantcornholio avatar Jul 14 '23 05:07 mutantcornholio

Tracking this issue at the moment https://github.com/mafintosh/tar-fs/issues/108. Setting the file ownership permissions manually and doing a docker cp into the container correctly preserves the permissions. From my testing it seems the tar-fs library is what's losing the ownership permissions.

cristianrgreco avatar Jul 14 '23 13:07 cristianrgreco