{"id":14986137,"url":"https://github.com/stefanscherer/windows-docker-machine","last_synced_at":"2025-05-16T09:03:06.544Z","repository":{"id":15373066,"uuid":"78009291","full_name":"StefanScherer/windows-docker-machine","owner":"StefanScherer","description":"Work with Windows containers and LCOW on Mac/Linux/Windows","archived":false,"fork":false,"pushed_at":"2023-05-24T08:09:02.000Z","size":4048,"stargazers_count":1117,"open_issues_count":15,"forks_count":155,"subscribers_count":29,"default_branch":"main","last_synced_at":"2025-05-16T09:02:59.785Z","etag":null,"topics":["docker-machine","lcow","vagrant","vagrantfile","windows-1803","windows-1809","windows-1903","windows-2019","windows-containers","windowscontainers"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StefanScherer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-01-04T11:20:43.000Z","updated_at":"2025-05-14T22:26:41.000Z","dependencies_parsed_at":"2024-04-14T16:58:49.030Z","dependency_job_id":"80f393ac-6fdd-4020-ab5a-fd70f9afe349","html_url":"https://github.com/StefanScherer/windows-docker-machine","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanScherer%2Fwindows-docker-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanScherer%2Fwindows-docker-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanScherer%2Fwindows-docker-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefanScherer%2Fwindows-docker-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StefanScherer","download_url":"https://codeload.github.com/StefanScherer/windows-docker-machine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501555,"owners_count":22081528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-machine","lcow","vagrant","vagrantfile","windows-1803","windows-1809","windows-1903","windows-2019","windows-containers","windowscontainers"],"created_at":"2024-09-24T14:12:23.506Z","updated_at":"2025-05-16T09:03:06.523Z","avatar_url":"https://github.com/StefanScherer.png","language":"PowerShell","readme":"# Windows Docker Machine\n[![Build status](https://ci.appveyor.com/api/projects/status/f1i6eotfeghj22u3?svg=true)](https://ci.appveyor.com/project/StefanScherer/windows-docker-machine)\n\nThis Vagrant environment creates a \"Docker Machine\" to work on your MacBook with\nWindows containers. You can easily switch between Docker Desktop Linux\ncontainers and the Windows containers.\n\n[![Docker Context asciinema](https://asciinema.org/a/8b0NKbNvpKxJhGThjMYCsSNbI.svg)](https://asciinema.org/a/8b0NKbNvpKxJhGThjMYCsSNbI)\n\n## Many flavors\n\nThere are several versions of Windows Server. This is where you\ndecide which Vagrant VM should be started.\n\n* `2022-box` - Windows Server 2022 (10.0.20348) LTS Channel, ___***prebuilt from Vagrant Cloud***___\n* `2022` - Windows Server 2022 (10.0.20348) LTS Channel\n* `2019-box` - Windows Server 2019 (10.0.17763) LTS Channel, ___***prebuilt from Vagrant Cloud***___\n* `2019` - Windows Server 2019 (10.0.17763) LTS Channel\n* `1903` - Windows Server, version 1903 (10.0.18362) Semi-Annual Channel\n* `1809` - Windows Server, version 1809 (10.0.17763) Semi-Annual Channel\n* `1803` - Windows Server, version 1803 (10.0.17134) Semi-Annual Channel\n* `2016-box` - Windows Server 2016 (10.0.14393) LTS channel, ___****prebuilt from Vagrant Cloud***___\n* `2016` - Windows Server 2016 (10.0.14393) LTS channel\n* `insider` - Windows Server Insider builds\n* `lcow` - Windows Server, version 1809 with LCOW enabled\n\nSo with a `vagrant up 2019` you spin up the LTS version, with `vagrant up 1903`\nthe 1903 semi-annual version and with `vagrant up insider` the Insider build.\n\nIf you don't want to run the **packer** step, you can run `vagrant up 2019-box`\nor `vagrant up 2022-box` to get your box image downloaded directly from Vagrant\nCloud. That uses the box images [windows_2019_docker], respectively\n[windows_2022_docker].\n\n[windows_2019_docker]: https://app.vagrantup.com/StefanScherer/boxes/windows_2019_docker\n[windows_2022_docker]: https://app.vagrantup.com/StefanScherer/boxes/windows_2022_docker\n\n## Tested environments\n\n* macOS with Vagrant 2.2.19\n  * VMware Fusion Pro 11.0.3\n  * VirtualBox 5.2.26 and 6.1.34\n* Windows with Vagrant 2.2.4\n  * VMware Workstation Pro 15.0.3\n  * (VirtualBox see issue\n    [#2](https://github.com/StefanScherer/windows-docker-machine/issues/2))\n  * (Hyper-V see issue\n    [#1](https://github.com/StefanScherer/windows-docker-machine/issues/1))\n\n## Getting started\n\nFirst you need a Windows Server VM for your hypervisor. I prefer\n\"Infrastructure as Code\", so every build step is available on GitHub.\n\n![packer vagrant docker](images/packer_vagrant_docker.png)\n\n1. (optional) **packer build** to build a Vagrant base box, it's like a Docker image, but\n   for Vagrant VM's. \n2. **vagrant up** to create a running VM instance of Windows Server, either using the\n   `packer build` or by using one of the pre-built Vagrant Cloud binaries\n   `2022-box`, `2019-box`, or `2016-box`.\n3. **docker run** to run Windows containers in that Windows VM\n\nStep 1 (building the headless Vagrant box) can be done with these steps:\n\n```bash\n$ git clone https://github.com/StefanScherer/packer-windows\n$ cd packer-windows\n\n$ packer build --only=vmware-iso windows_2022_docker.json\n$ vagrant box add windows_2022_docker windows_2022_docker_vmware.box\n\n- or -\n\n$ packer build --only=vmware-iso windows_2019_docker.json\n$ vagrant box add windows_2019_docker windows_2019_docker_vmware.box\n\n- or -\n\n$ packer build --only=vmware-iso --var iso_url=~/path-to-1903.iso windows_server_1903_docker.json\n$ vagrant box add windows_server_1903_docker windows_server_1903_docker_vmware.box\n\n- or -\n\n$ packer build --only=vmware-iso --var iso_url=~/path-to-1809.iso windows_server_1809_docker.json\n$ vagrant box add windows_server_1809_docker windows_server_1809_docker_vmware.box\n\n- or -\n\n$ packer build --only=vmware-iso --var iso_url=~/path-to-1803.iso windows_server_1803_docker.json\n$ vagrant box add windows_server_1803_docker windows_server_1803_docker_vmware.box\n\n- or -\n\n$ packer build --only=vmware-iso --var iso_url=~/path-to-insider.iso windows_server_insider_docker.json\n$ vagrant box add windows_server_insider_docker windows_server_insider_vmware_docker.box\n\n- or -\n\n$ packer build --only=vmware-iso --var iso_url=~/path-to-2016.iso windows_2016_docker.json\n$ vagrant box add windows_2016_docker windows_2016_docker_vmware.box\n```\n\nOf course you can build only the box version you need. If you are using VirtualBox instead of VMware,\nswap `vmware` for `virtualbox` in the vagrant commands above.\n\n## Working on macOS \u0026 Linux\n\n### Create the Docker Machine\n\nSpin up the headless Vagrant box you created earlier. It will create the TLS\ncertificates and a corresponding Docker context called `2022-box` or `2019-box`.\n\n```bash\n$ git clone https://github.com/StefanScherer/windows-docker-machine\n$ cd windows-docker-machine\n$ vagrant up --provider vmware_desktop 2019-box\n\n- or -\n\n$ vagrant up --provider virtualbox 2019-box\n```\n\nIf you want to use Windows Server 2022, type `2022-box` here instead.\n\n\n### List your new Docker machine\n\n```bash\n$ docker context ls\nNAME                DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT                ORCHESTRATOR\n2019-box            2019-box windows-docker-machine           tcp://192.168.65.130:2376\ndefault *           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock   https://localhost:6443 (default)   swarm\ndummy                                                         tcp://1.2.3.4:2375\n```\n\n### Switch to Windows containers\n\n```bash\n$ docker context use 2019-box\n```\n\nNow your Mac Docker client talks to the Windows Docker engine:\n\n```bash\n$ docker version\nClient: Docker Engine - Community\n Version:           19.03.0-beta1\n API version:       1.39 (downgraded from 1.40)\n Go version:        go1.12.1\n Git commit:        62240a9\n Built:             Thu Apr  4 19:15:32 2019\n OS/Arch:           darwin/amd64\n Experimental:      false\n\nServer: Docker Engine - Enterprise\n Engine:\n  Version:          18.09.5\n  API version:      1.39 (minimum version 1.24)\n  Go version:       go1.10.8\n  Git commit:       be4553c277\n  Built:            04/11/2019 06:43:04\n  OS/Arch:          windows/amd64\n  Experimental:     false\n```\n\n### Switch back to Docker Desktop\n\n```bash\n$ docker context use default\n```\n\nThis removes all DOCKER environment variables and you can use your Docker for\nMac installation.\n\n```bash\n$ docker version\nClient: Docker Engine - Community\n Version:           19.03.0-beta1\n API version:       1.39 (downgraded from 1.40)\n Go version:        go1.12.1\n Git commit:        62240a9\n Built:             Thu Apr  4 19:15:32 2019\n OS/Arch:           darwin/amd64\n Experimental:      false\n\nServer: Docker Engine - Community\n Engine:\n  Version:          18.09.2\n  API version:      1.39 (minimum version 1.12)\n  Go version:       go1.10.6\n  Git commit:       6247962\n  Built:            Sun Feb 10 04:13:06 2019\n  OS/Arch:          linux/amd64\n  Experimental:     false\n```\n\n### Mounting volumes from your Mac machine\n\nJust use `C:$(pwd)` to prepend a drive letter.\n\n```bash\n$ docker run -it -v C:$(pwd):C:$(pwd) mcr.microsoft.com/windows/servercore:1809 powershell\n```\n\nThis mounts the current working directory through the Windows VM into the\nWindows Container.\n\n### Accessing published ports of Windows containers\n\nWhen you run Windows containers with publish ports then you can use the IP\naddress of the Windows Docker host to access it. The `docker context` command in combination with `jq` can give your the IP address with a command. Alternatively `docker-machine ip` also gives you the IP address.\n\nExample: Run the whoami Windows container and open it in the default macOS\nbrowser.\n\n```\n$ docker run -d -p 8080:8080 stefanscherer/whoami\n$ open http://$(docker context inspect 2019-box | jq -r '.[0].Endpoints.docker.Host | .[6:] | .[:-5]'):8080\n\n- or -\n\n$ open http://$(docker-machine ip 2019-box):8080\n```\n\n## Working on Windows\n\nSpin up the headless Vagrant box you created earlier. It will create the TLS\ncertificates and a corresponding Docker context called `2022-box` or `2019-box`.\n\nIf you haven't worked with `docker context` yet, create the `.docker` directory\nin your user profile manually.\n\n```powershell\nPS C:\\\u003e mkdir $env:USERPROFILE\\.docker\n```\n\n### Create the Docker Machine\n\nChoose your hypervisor and start the VM\n\n```powershell\nPS C:\\\u003e git clone https://github.com/StefanScherer/windows-docker-machine\nPS C:\\\u003e cd windows-docker-machine\nPS C:\\\u003e vagrant up --provider vmware_desktop 2019-box\n\n- or -\n\nPS C:\\\u003e vagrant up --provider virtualbox 2019-box\n\n- or -\n\nPS C:\\\u003e vagrant up --provider hyperv 2019-box\n```\n\nIf you want to use Windows Server 2022, type `2022-box` here instead.\n\nNotice: The provider `hyperv` does mount the volumes with SMB into the Windows Server\nVM. It seems that there is a problem mounting that further into a Windows\ncontainer. The provisioning (creating the TLS certs and copying them back to the\nWindows host) will fail.\n\n### List your new Docker machine\n\n```powershell\nPS C:\\\u003e docker context ls\nNAME                DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT                ORCHESTRATOR\n2019-box            2019-box windows-docker-machine           tcp://192.168.65.130:2376\ndefault *           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock   https://localhost:6443 (default)   swarm\n```\n\n### Switch to Windows containers\n\n```powershell\nPS C:\\\u003e docker context use 2019-box\n```\n\nNow your Windows Docker client talks to the Windows Docker engine:\n\n```powershell\nPS C:\\\u003e docker version\nClient: Docker Engine - Community\n Version:           19.03.0-beta1\n API version:       1.39 (downgraded from 1.40)\n Go version:        go1.12.1\n Git commit:        62240a9\n Built:             Thu Apr  4 19:15:32 2019\n OS/Arch:           darwin/amd64\n Experimental:      false\n\nServer: Docker Engine - Enterprise\n Engine:\n  Version:          18.09.5\n  API version:      1.39 (minimum version 1.24)\n  Go version:       go1.10.8\n  Git commit:       be4553c277\n  Built:            04/11/2019 06:43:04\n  OS/Arch:          windows/amd64\n  Experimental:     false\n```\n\n### Switch to back to Docker for Windows\n\n```powershell\nPS C:\\\u003e docker context use default\n```\n\nThis removes all DOCKER environment variables and you can use your Docker for\nWindows installation.\n\n```powershell\nPS C:\\\u003e docker version\nClient: Docker Engine - Community\n Version:           19.03.0-beta1\n API version:       1.39 (downgraded from 1.40)\n Go version:        go1.12.1\n Git commit:        62240a9\n Built:             Thu Apr  4 19:15:32 2019\n OS/Arch:           darwin/amd64\n Experimental:      false\n\nServer: Docker Engine - Community\n Engine:\n  Version:          18.09.2\n  API version:      1.39 (minimum version 1.12)\n  Go version:       go1.10.6\n  Git commit:       6247962\n  Built:            Sun Feb 10 04:13:06 2019\n  OS/Arch:          linux/amd64\n  Experimental:     false\n\n```\n\n### Mounting volumes from your Windows machine\n\nJust use `$(pwd)` in PowerShell.\n\n```powershell\nPS C:\\\u003e docker run -it -v \"$(pwd):$(pwd)\" mcr.microsoft.com/windows/servercore:1809 powershell\n```\n\nThis mounts the current working directory through the Windows VM into the\nWindows Container.\n\n### Accessing published ports of Windows containers\n\nWhen you run Windows containers with publish ports then you can use the IP\naddress of the Windows Docker host to access it. The `docker context inspect` command can\ngive your the IP address with a command.\n\nExample: Run the whoami Windows container and open it in the default browser.\n\n```powershell\nPS C:\\\u003e docker run -d -p 8080:8080 stefanscherer/whoami\nPS C:\\\u003e start http://$(docker-machine ip 2019-box):8080\n```\n\n## Further commands\n\nHere is a list of `vagrant` and `docker` commands for typical actions.\nI use a `bash` function\n[`dm` in my dotfiles repo](https://github.com/StefanScherer/dotfiles/blob/4517216a56708acad5c2c0809f6bfafbd880aea3/.functions#L140-L182)\nto simplify all the tasks without switching to the Vagrant folder each time.\nThe `dm` started as a shortcut for `docker-machine` commands. I have [updated the function](https://github.com/StefanScherer/dotfiles/commit/2e771b023d97d9ec91fb20633204903c9f3b21eb#diff-e39ded4129d0efa321423853506c0116) to work with `docker context`, but rolled back for now as I prefer the environment variables to have different \"contexts\" per terminal tab.\n\n| dm shortcut                    | Vagrant / Docker command             |\n| ------------------------------ | ------------------------------------ |\n| `dm start 2019-box`            | `vagrant up --provider xxx 2019-box` |\n| `dm regenerate-certs 2019-box` | `vagrant provision 2019-box`         |\n| `dm stop 2019-box`             | `vagrant halt 2019-box`              |\n| `dm start 2019-box`            | `vagrant up 2019-box`                |\n| `dm rdp 2019-box`              | `vagrant rdp 2019-box`               |\n| `dm rm [-f] 2019-box`          | `vagrant destroy [-f] 2019-box`      |\n| `dm 2019-box`                  | `docker context use 2019-box` or \u003cbr/\u003e `eval $(docker-machine env 2019-box)`       |\n| `dm ip 2019-box`               | \u003ccode\u003edocker context inspect 2019-box \u0026#124; jq -r '.[0].Endpoints.docker.Host \u0026#124; .[6:] \u0026#124; .[:-5]'\u003c/code\u003e or \u003cbr/\u003e `docker-machine ip 2019-box` |\n\n## Insider builds\n\nIf you want to follow the Windows Server Insider builds then this is for you. It\nis tested on a Mac with the following steps.\n\n1. Register at Windows Insider program https://insider.windows.com\n\n2. Download the Windows Server ISO from\n   https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver?wa=wsignin1.0\n\n3. Build the Vagrant basebox with Packer\n\n```bash\ngit clone https://github.com/StefanScherer/packer-windows\ncd packer-windows\npacker build --only=vmware-iso --var iso_url=~/Downloads/Windows_InsiderPreview_Server_en-us_18356.iso windows_server_insider_docker.json\nvagrant box add windows_server_insider_docker windows_server_insider_docker_vmware.box\n```\n\nThen spin up your Insider machine with\n\n```\nvagrant up insider\n```\n\nThis Vagrant box has Docker installed and the following base\nimages are already pulled from Docker Hub:\n\n* mcr.microsoft.com/windows/servercore/insider\n* mcr.microsoft.com/windows/nanoserver/insider\n\n## LCOW\n\nYou can try the Linux Container on Windows feature in a separate machine `lcow`.\nIt is preconfigured to use the Windows Server, version 1903. But you can\nalso use Windows Insider Server Preview as base box.\n\n```\nvagrant up lcow\ndocker context use lcow\ndocker run alpine uname -a\n```\n\n## Cleanup\n\nIf you want to cleanup your machine again after playing with Windows Containers, use the following commands\n\n```\nvagrant destroy -f\nvagrant box remove StefanScherer/windows_2019_docker\ndocker context rm 2019-box\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanscherer%2Fwindows-docker-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanscherer%2Fwindows-docker-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanscherer%2Fwindows-docker-machine/lists"}