vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

Vagrant in WSL2 with Docker uses wrong volumes paths

Open fabm3n opened this issue 3 years ago • 2 comments

Vagrant version

Vagrant 2.2.18 (Installed in WSL2)

Host operating system

Windows 11 Version 21H2 Build 22000.348

In WSL2: Ubuntu 20.04 LTS

Guest operating system

Ubuntu

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.define "test" do |test|
    test.vm.synced_folder ".", "/vagrant", disabled: true

    test.vm.provider "docker" do |d|
      d.image = "ubuntu"
      d.name = "test"
      d.volumes = ["/mnt/c/Users/info/development/test:/home/vagrant/test:ro"]
      # d.volumes = ["/home/fabian/development/test:/home/vagrant/test:ro"]
      d.remains_running = false
    end
  end
end

Debug output

(No full debug output because i have a lot of docker containers and each docker container inspect output is in these logs)

Files on Windows Drive (/mnt/c/....):

INFO interface: output: Creating the container... INFO interface: output: ==> test: Creating the container... ==> test: Creating the container... INFO interface: detail: Name: test INFO interface: detail: test: Name: test test: Name: test INFO interface: detail: Image: ubuntu INFO interface: detail: test: Image: ubuntu test: Image: ubuntu INFO interface: detail: Volume: /mnt/c/Users/info/development/test:/home/vagrant/test:ro INFO interface: detail: test: Volume: /mnt/c/Users/info/development/test:/home/vagrant/test:ro test: Volume: /mnt/c/Users/info/development/test:/home/vagrant/test:ro INFO subprocess: Starting process: ["/usr/bin/docker", "run", "--name", "test", "-d", "-v", "///nt/c/Users/info/development/test:/home/vagrant/test:ro", "ubuntu"]

Files on WSL2 Drive (/home/fabian/...): INFO interface: output: Creating the container... INFO interface: output: ==> test: Creating the container... ==> test: Creating the container... INFO interface: detail: Name: test INFO interface: detail: test: Name: test test: Name: test INFO interface: detail: Image: ubuntu INFO interface: detail: test: Image: ubuntu test: Image: ubuntu INFO interface: detail: Volume: /home/fabian/development/test:/home/vagrant/test:ro INFO interface: detail: test: Volume: /home/fabian/development/test:/home/vagrant/test:ro test: Volume: /home/fabian/development/test:/home/vagrant/test:ro INFO subprocess: Starting process: ["/usr/bin/docker", "run", "--name", "test", "-d", "-v", "///ome/fabian/development/test:/home/vagrant/test:ro", "ubuntu"]

Expected behavior

The volume should be "/mnt/c/Users/info/development/test:/home/vagrant/test:ro". Same with "/home/fabian/development/test:/home/vagrant/test:ro" as volume.

Actual behavior

The volume path is wront so it can't be attached to the container.

Steps to reproduce

  1. Install WSL2 with Docker
  2. Start a container with a volume

If you need any informations, feel free to ask.

fabm3n avatar Nov 29 '21 17:11 fabm3n

I can confirm this bug in Vagrant 2.2.19 (Installed in WSL2)

star3am avatar May 27 '22 21:05 star3am

Remains a problem in WSL2 - I managed to work around this moving the volume to create_args and running on Windows Docker Desktop without WSL2

      config.vm.provider "docker" do |docker, override|
        override.vm.box        = nil
        docker.build_dir       = "."
        docker.remains_running = true
        docker.has_ssh         = true
        docker.privileged      = true
        # BUG: https://github.com/hashicorp/vagrant/issues/12602
        # moved to create_args
        # docker.volumes         = ['/sys/fs/cgroup:/sys/fs/cgroup:rw']
        docker.create_args     = ['-v', '/sys/fs/cgroup:/sys/fs/cgroup:rw', '--cgroupns=host', '--tmpfs=/tmp:exec', '--tmpfs=/var/lib/docker:mode=0777,dev,size=15g,suid,exec', '--tmpfs=/run', '--tmpfs=/run/lock'] # '--memory=10g', '--memory-swap=14g', '--oom-kill-disable'
        # Uncomment to force arm64 for testing images on Intel
        # docker.create_args = ["--platform=linux/arm64"]
        docker.env             = { "PROVIDER": "docker", "NAME": "hashiqube" }
      end

ref: https://github.com/servian/hashiqube/blob/master/Vagrantfile#L143

star3am avatar May 28 '22 05:05 star3am