Code Monkey home page Code Monkey logo

Comments (4)

libc avatar libc commented on June 25, 2024 2

@jaraco I sort-of made it work, it's not as easy as just building the box.

For packer-windows you need the following changes:

diff --git a/windows_2019_docker.json b/windows_2019_docker.json
index 921e1e0..e6d89f0 100644
--- a/windows_2019_docker.json
+++ b/windows_2019_docker.json
@@ -1,7 +1,6 @@
 {
   "builders": [
     {
-      "accelerator": "kvm",
       "boot_wait": "0s",
       "communicator": "winrm",
       "cpus": 2,
@@ -15,7 +14,8 @@
         "./scripts/microsoft-updates.bat",
         "./scripts/win-updates.ps1"
       ],
-      "headless": true,
+      "headless": false,
+      "display": "cocoa",
       "iso_checksum": "{{user `iso_checksum`}}",
       "iso_url": "{{user `iso_url`}}",
       "memory": "{{user `memory`}}",
@@ -25,6 +25,10 @@
           "-drive",
           "file=windows_2019_docker-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1"
         ],
+        [
+          "-drive",
+          "file=windows.iso,media=cdrom,index=2"
+        ],
         [
           "-drive",
           "file={{ user `virtio_win_iso` }},media=cdrom,index=3"
  • kvm is not supported on m1 qemu (for obvious reasons),
  • headless and display turns of headless mode for packer. Without them it's really hard to tell if it's working, the build took 12 hours on my machine, so I highly recommend enabling it
  • windows.iso is a copy of iso_url downloaded locally. Specifying any drives overrides default config, and machine won't boot (no way to tell this in headless mode), so windows iso needs to be here specifically. You can see details here StefanScherer/packer-windows#270 (comment)

Then vagrant box add windows_2019_docker windows_2019_docker_libvirt.box will add the box.

I had to change vagrant-qemu code. These lines https://github.com/ppggff/vagrant-qemu/blob/36eb93afc951650c2bc801ec989f8c221f36f077/lib/vagrant-qemu/action/start_instance.rb#L43-L46 should be

            host_ip = ""
            # host_ip = "#{options[:host_ip]}:" if options[:host_ip]
            guest_ip = ""
            # guest_ip = "#{options[:guest_ip]}:" if options[:guest_ip]
            result.push("#{options[:protocol]}:#{host_ip}:#{options[:host]}-#{guest_ip}:#{options[:guest]}")

my version of qemu wasn't happy about host in port forwarding rules.

Vagrant file changes are:

diff --git a/Vagrantfile b/Vagrantfile
index 2a711bf..cd88469 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -8,7 +8,8 @@ Vagrant.configure("2") do |config|

   config.vm.synced_folder ".", "/vagrant", disabled: true
   home = ENV['HOME'].gsub('\\', '/')
-  config.vm.synced_folder home, home
+  config.vm.synced_folder home, home, type: "smb", smb_host: "10.0.2.2"
+  config.vm.network "forwarded_port", guest: 2376, host: 2376

   config.vm.define "2016", autostart: false do |cfg|
     cfg.vm.box     = "windows_2016_docker"
@@ -107,6 +108,18 @@ Vagrant.configure("2") do |config|
     v.customize ["modifyvm", :id, "--paravirtprovider", "hyperv"]
   end

+  config.vm.provider "qemu" do |v, override|
+    v.gui = false
+    v.memory = 2048
+    v.cpus = 2
+    v.linked_clone = true
+    v.arch = "x86_64"
+    v.machine = "pc"
+    v.cpu = "max"
+    v.net_device = "virtio-net-pci"
+    v.qemu_dir = "/nix/store/azrccc44b425xh1v5bk9sxi2hf15v8mj-qemu-7.0.0/share/qemu/"
+  end
+
   config.vm.provider "hyperv" do |v|
     v.cpus = 2
     v.maxmemory = 2048
  • synced_folder needs smb_host specified because ping is not implement somehow, as described in the vagrant-qemu's README
  • forwarded_port I added to easily open docker's tcp port. This wouldn't get tricky if you want to run more than one box, but also can be avoided if network is properly setup. But this was the easiest path forward for me
  • qemu_dir is set to /opt/homebrew/share/qemu by default, if you're using aarch64 homebrew, you can probably keep the default. I had to change it to my installation

I also changed .ps1 script to set machine ip to 127.0.0.1 (forwarded port):

diff --git a/scripts/create-machine.ps1 b/scripts/create-machine.ps1
index 174cacb..ab60c31 100644
--- a/scripts/create-machine.ps1
+++ b/scripts/create-machine.ps1
@@ -9,13 +9,14 @@ if (!(Test-Path $env:USERPROFILE\.docker)) {
 $ipAddresses = ((Get-NetIPAddress -AddressFamily IPv4).IPAddress) -Join ','

 if (!$machineIp) {
-  $machineIp=(Get-NetIPAddress -AddressFamily IPv4 `
-    | Where-Object -FilterScript { `
-      ( ! ($_.InterfaceAlias).StartsWith("vEthernet (") ) `
-      -And $_.IPAddress -Ne "127.0.0.1" `
-      -And $_.IPAddress -Ne "10.0.2.15" `
-      -And !($_.IPAddress.StartsWith("169.254.")) `
-    }).IPAddress
+  $machineIp="127.0.0.1"
+  # $machineIp=(Get-NetIPAddress -AddressFamily IPv4 `
+  #   | Where-Object -FilterScript { `
+  #     ( ! ($_.InterfaceAlias).StartsWith("vEthernet (") ) `
+  #     -And $_.IPAddress -Ne "127.0.0.1" `
+  #     -And $_.IPAddress -Ne "10.0.2.15" `
+  #     -And !($_.IPAddress.StartsWith("169.254.")) `
+  #   }).IPAddress
 } else {
   $ipAddresses = "$ipAddresses,$machineIp"
 }

I was able to run docker after these changes:

windows-docker-machine]$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                 KUBERNETES ENDPOINT   ORCHESTRATOR
2019                moby                2019 windows-docker-machine               tcp://127.0.0.1:2376

windows-docker-machine]$ docker --context 2019 run --rm -it mcr.microsoft.com/windows:1809
Microsoft Windows [Version 10.0.17763.3287]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\>dir
 Volume in drive C has no label.
 Volume Serial Number is 4607-C090

 Directory of C:\

04/21/2022  06:12 PM             5,510 License.txt

I hope that helps.

from windows-docker-machine.

jaraco avatar jaraco commented on June 25, 2024 1

Today I learned that UTM is backed by qemu, which has a vagrant provider. I tried spinning up the box using qemu, but without success (reasonably, because the images haven't been built):

$ brew install qemu vagrant
$ vagrant plugin install vagrant-qemu
windows-docker-machine main $ vagrant up --provider qemu 2019-box
Bringing machine '2019-box' up with 'qemu' provider...
==> 2019-box: Box 'StefanScherer/windows_2019_docker' could not be found. Attempting to find and install...
    2019-box: Box Provider: libvirt
    2019-box: Box Version: >= 0
==> 2019-box: Loading metadata for box 'StefanScherer/windows_2019_docker'
    2019-box: URL: https://vagrantcloud.com/StefanScherer/windows_2019_docker
The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Vagrant Cloud, make sure the box is
released.

Name: StefanScherer/windows_2019_docker
Address: https://vagrantcloud.com/StefanScherer/windows_2019_docker
Requested provider: ["libvirt"]

Maybe someone could build the box for the provider?

from windows-docker-machine.

Antonytm avatar Antonytm commented on June 25, 2024 1

@libc

And how is the performance of this setup?
Is it possible to work?

from windows-docker-machine.

jaraco avatar jaraco commented on June 25, 2024

I believe it is not. The procedures herein rely on virtualbox, which doesn't support Apple Silicon. It's possible it could be made to work with VMWare or Parallels or UTM, which can run Windows VMs, but I wouldn't know how to do that.

from windows-docker-machine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.