'How to mount a directory such that it has same UID/GID in host as well as container?

I've been scratching my head and have re-read the man-page for uidmap, gidmap, /etc/subuid, and /etc/subgid multiple times.

I need to mount a source-code directory into a container such that (a) processes within the container have read/write access to the files, as well as (b) processes on the host.

I'm mounting the directory using -v hostDir:containerDir:U and files that are initially owned by userID 1000 end-up as owned by userID 1000999 after the container exits.

How do I set this up properly? The files should be available on the host as well as the container with UID/GID=1000/1000



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source