microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

Allow Running Docker Compose inside of WSL2 with VS2022 #406

Closed MDendura closed 4 months ago

MDendura commented 8 months ago

I would like to know if it is possible to configure Container Tools to start Docker Compose within WSL2, with access to the WSL2 filesystem, just as you could do the following manually from a terminal:

C:\myproject> wsl
root@MACHINENAME:/mnt/c/myproject# docker compose up

My use-case is perhaps a little strange I need to be able to attach a volume to my container that points to a mapped network drive on the Windows host machine via the mount in WSL2. The network location referred to by the mapped drive is a Windows Administrative Share (\\someserver\d$) due to some historic/centralised IT setup and has been assigned the drive letter D: on the host Windows machine.

The docker-compose.yml file I am trying to use from Visual Studio 2022 is as follows, with a few of the labels changed for privacy reasons. Both containers are Linux-based:

version: "3.4"
name: myapp
services:
  webapi:
    image: ${DOCKER_REGISTRY-}webapi
    depends_on:
      - backendapi
    build:
      context: .
      dockerfile: WebApi/Dockerfile
    links:
      - "backendapi:backend"
    environment:
      - Backend__BaseUrl=http://backend:8080/

  backendapi:
    # Some lines removed for brevity
    ports:
      - "8080:8080"
    volumes:
      - "/mnt/d/InputFiles/:/app/release/inputfiles:ro"
    image: "myapp-backend-api"

Testing the backendapi container separately, I've found that trying to mount a volume using a Windows-style path without WSL results in the /app/release/inputfiles directory appearing empty to the container.

Only starting the container from inside of WSL (as shown above) and using the WSL mount in the style given in the above docker-compose.yml file allows the running backendapi container to see the files present on the share.

I have tried using a CIFS mount but this seems to require storing user credentials within my Docker Compose file and is something I would rather avoid. I have also tried configuring a Global SMB Mapping pointing to the share but this doesn't work either.

fiveisprime commented 4 months ago

We shipped an update to allow for this in 17.10 Preview 1. See #417 for more information on how to configure this. Let us know in that issue if you run into anything.