Docker Community Forums

Share and learn in the Docker community.

Docker Desktop WSL2 volume mapping not working as expected

I’m running Docker Desktop with WSL2 backend.

I’m trying to run a docker-compose.yml which looks like the following:

version: '3.8'
services:
  foo-service:
    volumes:
      - /home/foo:/var/lib/foo

A docker inspect on the container gives:

"HostConfig": {
            "Binds": [
                "/home/foo:/var/lib/foo:rw"
            ]
[..]
"Mounts": [                                        
    {                                              
        "Type": "bind",                            
        "Source": "/home/foo",
        "Destination": "/var/lib/foo",           
        "Mode": "rw",                              
        "RW": true,                                
        "Propagation": "rprivate"                  
    }                                              
],   

So when I do a docker-compose up I expect that the volume mapping could be found under \\wsl$\docker-desktop\home\foo but the \home directory is empty whereas the volumes under \\wsl$\docker-desktop-data\mnt\wsl\docker-desktop-data\data\docker\volumes are created.

When I connect Docker Desktop with my WSL2 Ubuntu distribution and run the compose file from inside the mapping is created successfully.