Permissions issue writing to Docker volume inside WSL2 filesystem

I have recently switched back to Windows and am implementing a WSL2 setup (Ubuntu) for WordPress developmnent using docker compose:


    services:
      db:
        command: '--default-authentication-plugin=mysql_native_password'
        volumes:
          - db_data:/var/lib/mysql
        restart: always
        environment:
          - MYSQL_ROOT_PASSWORD=***
          - MYSQL_DATABASE=wordpress
          - MYSQL_USER=wordpress
          - MYSQL_PASSWORD=***
        expose:
          - 3306
          - 33060
      wordpress:
        image: wordpress:latest
        volumes:
          - ./wp:/var/www/html
        ports:
          - 80:80
          - 443:443
        restart: always
        environment:
          - WORDPRESS_DB_HOST=db
          - WORDPRESS_DB_USER=wordpress
          - WORDPRESS_DB_PASSWORD=***
          - WORDPRESS_DB_NAME=wordpress
      phpmyadmin:
        depends_on:
          - db
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8080:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: ***
    volumes:
      db_data:

The issue I’m facing is that I’m unable to write to the /wp/ folder with the Ubuntu user I have, whether via the command line or VSCode. So to be clear, my WSL2 filesystem looks like:

/home/myuser/sites/myproject/
  docker-compose.yml
  /wp/ # Docker volume mount

For example, I need to be able to clone Git repositories into the volume for the various plugins I work on, run build tooling etc.

My Ubuntu user has been added to the www-data group --as this is the user/group owning the files – as well as the docker group, but that hasn’t made any difference. I am convinced that I am missing something here?

Grateful for any pointers or suggestions for a better approach. I feel like I am missing something obvious!

Can you share your process?

Note docker exec -u www-data ${container name/id} bash would open bash inside the container as that particular user, resulting in files being cloned or checked out as the user. Would that solve your issue?

hi @meyay thanks for the reply.

My goal is to be able to spin up the Docker environment and be able to access the files on the mounted volume via my existing terminal (zsh on the WSL2 Ubuntu) for git, gulp/webpack, composer etc as well as editing/creating files with Visual Studio Code.

What you’re suggesting implies I’d only be able to use a basic bash shell without all of the various development tools and dependencies I have installed in Ubuntu, is that correct or am I off there?

Adding user: 1000:33 (my user and www-data group ids) to the wordpress container in the above file appears to resolve the issue

As you said you need to be able to clone Git repositories into the volume, I assume you are going to perform the operation inside the container.

But now it seems that you are talking about a host-path in WSL2 that you bind mount into the container, and you are working in WSL2 and want your container to be able to access the files. Of course what I suggested does not fit this process.