How to mount volumes with local user ownership

Hi there.

I’ve built an image in which there is a local user foo (uid 1000, gid 1000) running a program.
This piece of code saves data in the directory /home/foo/data of the container.

When mounting the container, I want to persist the data on the machine on which I’m running docker, therefore I’ve used this approach in docker-compose.yml

version: "3.3"

services:
  
  jupyterlab:
    image: "my:customimage"
    container_name: "foo-container"
    volumes:
      - "$PWD/data:/home/foo/data"

Two issues occur when running this:

  1. The container cannot save files in the $PWD/data folder, because it is created at startup by Docker with root ownership
  2. If I manually change $PWD/data ownership to my user’s (which I would like not to do) foo is still not able to write in there because it has a different uid

Is there a possible approach to accomplish what I’m trying to do?