Editing files created by a container

I have a container setup with docker compose where I mount my project’s dir as a volume to be able to access it in the container.

  app:
    container_name: app
    build:
      context: ./docker/app
    volumes:
      - ./:/var/www/app

The project itself is located in the WSL folder on Windows.

If I create a file from Windows directly in the WSL folder I can edit it just fine, but if I create it from inside of the container then I am unable to edit the file from Windows.

Here’s how the file permissions look like if I do ls inside of the container:

-rw-r--r--  1 root root    0 May 28 11:32 file-created-in-container.txt
-rw-r--r--  1 1000 1000    0 May 28 11:31 file-created-in-windows.txt

Is there any way to deal with this?

Since your container started as root (user ID is 0), when you create a file in the container you need to be root on the host to edit it. You can change to user id in the container by using “user: 1000” in the compose file i the service definition, or enter the WSL distribution from command line and edit the file as root.