• Stars
    star
    1,024
  • Rank 43,397 (Top 0.9 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Work with Windows containers and LCOW on Mac/Linux/Windows

Windows Docker Machine

Build status

This Vagrant environment creates a "Docker Machine" to work on your MacBook with Windows containers. You can easily switch between Docker Desktop Linux containers and the Windows containers.

Docker Context asciinema

Many flavors

There are several versions of Windows Server. This is where you decide which Vagrant VM should be started.

  • 2022-box - Windows Server 2022 (10.0.20348) LTS Channel, prebuilt from Vagrant Cloud
  • 2022 - Windows Server 2022 (10.0.20348) LTS Channel
  • 2019-box - Windows Server 2019 (10.0.17763) LTS Channel, prebuilt from Vagrant Cloud
  • 2019 - Windows Server 2019 (10.0.17763) LTS Channel
  • 1903 - Windows Server, version 1903 (10.0.18362) Semi-Annual Channel
  • 1809 - Windows Server, version 1809 (10.0.17763) Semi-Annual Channel
  • 1803 - Windows Server, version 1803 (10.0.17134) Semi-Annual Channel
  • 2016-box - Windows Server 2016 (10.0.14393) LTS channel, *prebuilt from Vagrant Cloud
  • 2016 - Windows Server 2016 (10.0.14393) LTS channel
  • insider - Windows Server Insider builds
  • lcow - Windows Server, version 1809 with LCOW enabled

So with a vagrant up 2019 you spin up the LTS version, with vagrant up 1903 the 1903 semi-annual version and with vagrant up insider the Insider build.

If you don't want to run the packer step, you can run vagrant up 2019-box or vagrant up 2022-box to get your box image downloaded directly from Vagrant Cloud. That uses the box images windows_2019_docker, respectively windows_2022_docker.

Tested environments

  • macOS with Vagrant 2.2.19
    • VMware Fusion Pro 11.0.3
    • VirtualBox 5.2.26 and 6.1.34
  • Windows with Vagrant 2.2.4
    • VMware Workstation Pro 15.0.3
    • (VirtualBox see issue #2)
    • (Hyper-V see issue #1)

Getting started

First you need a Windows Server VM for your hypervisor. I prefer "Infrastructure as Code", so every build step is available on GitHub.

packer vagrant docker

  1. (optional) packer build to build a Vagrant base box, it's like a Docker image, but for Vagrant VM's.
  2. vagrant up to create a running VM instance of Windows Server, either using the packer build or by using one of the pre-built Vagrant Cloud binaries 2022-box, 2019-box, or 2016-box.
  3. docker run to run Windows containers in that Windows VM

Step 1 (building the headless Vagrant box) can be done with these steps:

$ git clone https://github.com/StefanScherer/packer-windows
$ cd packer-windows

$ packer build --only=vmware-iso windows_2022_docker.json
$ vagrant box add windows_2022_docker windows_2022_docker_vmware.box

- or -

$ packer build --only=vmware-iso windows_2019_docker.json
$ vagrant box add windows_2019_docker windows_2019_docker_vmware.box

- or -

$ packer build --only=vmware-iso --var iso_url=~/path-to-1903.iso windows_server_1903_docker.json
$ vagrant box add windows_server_1903_docker windows_server_1903_docker_vmware.box

- or -

$ packer build --only=vmware-iso --var iso_url=~/path-to-1809.iso windows_server_1809_docker.json
$ vagrant box add windows_server_1809_docker windows_server_1809_docker_vmware.box

- or -

$ packer build --only=vmware-iso --var iso_url=~/path-to-1803.iso windows_server_1803_docker.json
$ vagrant box add windows_server_1803_docker windows_server_1803_docker_vmware.box

- or -

$ packer build --only=vmware-iso --var iso_url=~/path-to-insider.iso windows_server_insider_docker.json
$ vagrant box add windows_server_insider_docker windows_server_insider_vmware_docker.box

- or -

$ packer build --only=vmware-iso --var iso_url=~/path-to-2016.iso windows_2016_docker.json
$ vagrant box add windows_2016_docker windows_2016_docker_vmware.box

Of course you can build only the box version you need. If you are using VirtualBox instead of VMware, swap vmware for virtualbox in the vagrant commands above.

Working on macOS & Linux

Create the Docker Machine

Spin up the headless Vagrant box you created earlier. It will create the TLS certificates and a corresponding Docker context called 2022-box or 2019-box.

$ git clone https://github.com/StefanScherer/windows-docker-machine
$ cd windows-docker-machine
$ vagrant up --provider vmware_desktop 2019-box

- or -

$ vagrant up --provider virtualbox 2019-box

If you want to use Windows Server 2022, type 2022-box here instead.

List your new Docker machine

$ docker context ls
NAME                DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT                ORCHESTRATOR
2019-box            2019-box windows-docker-machine           tcp://192.168.65.130:2376
default *           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock   https://localhost:6443 (default)   swarm
dummy                                                         tcp://1.2.3.4:2375

Switch to Windows containers

$ docker context use 2019-box

Now your Mac Docker client talks to the Windows Docker engine:

$ docker version
Client: Docker Engine - Community
 Version:           19.03.0-beta1
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.1
 Git commit:        62240a9
 Built:             Thu Apr  4 19:15:32 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Enterprise
 Engine:
  Version:          18.09.5
  API version:      1.39 (minimum version 1.24)
  Go version:       go1.10.8
  Git commit:       be4553c277
  Built:            04/11/2019 06:43:04
  OS/Arch:          windows/amd64
  Experimental:     false

Switch back to Docker Desktop

$ docker context use default

This removes all DOCKER environment variables and you can use your Docker for Mac installation.

$ docker version
Client: Docker Engine - Community
 Version:           19.03.0-beta1
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.1
 Git commit:        62240a9
 Built:             Thu Apr  4 19:15:32 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Mounting volumes from your Mac machine

Just use C:$(pwd) to prepend a drive letter.

$ docker run -it -v C:$(pwd):C:$(pwd) mcr.microsoft.com/windows/servercore:1809 powershell

This mounts the current working directory through the Windows VM into the Windows Container.

Accessing published ports of Windows containers

When you run Windows containers with publish ports then you can use the IP address 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.

Example: Run the whoami Windows container and open it in the default macOS browser.

$ docker run -d -p 8080:8080 stefanscherer/whoami
$ open http://$(docker context inspect 2019-box | jq -r '.[0].Endpoints.docker.Host | .[6:] | .[:-5]'):8080

- or -

$ open http://$(docker-machine ip 2019-box):8080

Working on Windows

Spin up the headless Vagrant box you created earlier. It will create the TLS certificates and a corresponding Docker context called 2022-box or 2019-box.

If you haven't worked with docker context yet, create the .docker directory in your user profile manually.

PS C:\> mkdir $env:USERPROFILE\.docker

Create the Docker Machine

Choose your hypervisor and start the VM

PS C:\> git clone https://github.com/StefanScherer/windows-docker-machine
PS C:\> cd windows-docker-machine
PS C:\> vagrant up --provider vmware_desktop 2019-box

- or -

PS C:\> vagrant up --provider virtualbox 2019-box

- or -

PS C:\> vagrant up --provider hyperv 2019-box

If you want to use Windows Server 2022, type 2022-box here instead.

Notice: The provider hyperv does mount the volumes with SMB into the Windows Server VM. It seems that there is a problem mounting that further into a Windows container. The provisioning (creating the TLS certs and copying them back to the Windows host) will fail.

List your new Docker machine

PS C:\> docker context ls
NAME                DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT                ORCHESTRATOR
2019-box            2019-box windows-docker-machine           tcp://192.168.65.130:2376
default *           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock   https://localhost:6443 (default)   swarm

Switch to Windows containers

PS C:\> docker context use 2019-box

Now your Windows Docker client talks to the Windows Docker engine:

PS C:\> docker version
Client: Docker Engine - Community
 Version:           19.03.0-beta1
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.1
 Git commit:        62240a9
 Built:             Thu Apr  4 19:15:32 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Enterprise
 Engine:
  Version:          18.09.5
  API version:      1.39 (minimum version 1.24)
  Go version:       go1.10.8
  Git commit:       be4553c277
  Built:            04/11/2019 06:43:04
  OS/Arch:          windows/amd64
  Experimental:     false

Switch to back to Docker for Windows

PS C:\> docker context use default

This removes all DOCKER environment variables and you can use your Docker for Windows installation.

PS C:\> docker version
Client: Docker Engine - Community
 Version:           19.03.0-beta1
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.1
 Git commit:        62240a9
 Built:             Thu Apr  4 19:15:32 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Mounting volumes from your Windows machine

Just use $(pwd) in PowerShell.

PS C:\> docker run -it -v "$(pwd):$(pwd)" mcr.microsoft.com/windows/servercore:1809 powershell

This mounts the current working directory through the Windows VM into the Windows Container.

Accessing published ports of Windows containers

When you run Windows containers with publish ports then you can use the IP address of the Windows Docker host to access it. The docker context inspect command can give your the IP address with a command.

Example: Run the whoami Windows container and open it in the default browser.

PS C:\> docker run -d -p 8080:8080 stefanscherer/whoami
PS C:\> start http://$(docker-machine ip 2019-box):8080

Further commands

Here is a list of vagrant and docker commands for typical actions. I use a bash function dm in my dotfiles repo to simplify all the tasks without switching to the Vagrant folder each time. The dm started as a shortcut for docker-machine commands. I have updated the function to work with docker context, but rolled back for now as I prefer the environment variables to have different "contexts" per terminal tab.

dm shortcut Vagrant / Docker command
dm start 2019-box vagrant up --provider xxx 2019-box
dm regenerate-certs 2019-box vagrant provision 2019-box
dm stop 2019-box vagrant halt 2019-box
dm start 2019-box vagrant up 2019-box
dm rdp 2019-box vagrant rdp 2019-box
dm rm [-f] 2019-box vagrant destroy [-f] 2019-box
dm 2019-box docker context use 2019-box or
eval $(docker-machine env 2019-box)
dm ip 2019-box docker context inspect 2019-box | jq -r '.[0].Endpoints.docker.Host | .[6:] | .[:-5]' or
docker-machine ip 2019-box

Insider builds

If you want to follow the Windows Server Insider builds then this is for you. It is tested on a Mac with the following steps.

  1. Register at Windows Insider program https://insider.windows.com

  2. Download the Windows Server ISO from https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewserver?wa=wsignin1.0

  3. Build the Vagrant basebox with Packer

git clone https://github.com/StefanScherer/packer-windows
cd packer-windows
packer build --only=vmware-iso --var iso_url=~/Downloads/Windows_InsiderPreview_Server_en-us_18356.iso windows_server_insider_docker.json
vagrant box add windows_server_insider_docker windows_server_insider_docker_vmware.box

Then spin up your Insider machine with

vagrant up insider

This Vagrant box has Docker installed and the following base images are already pulled from Docker Hub:

  • mcr.microsoft.com/windows/servercore/insider
  • mcr.microsoft.com/windows/nanoserver/insider

LCOW

You can try the Linux Container on Windows feature in a separate machine lcow. It is preconfigured to use the Windows Server, version 1903. But you can also use Windows Insider Server Preview as base box.

vagrant up lcow
docker context use lcow
docker run alpine uname -a

Cleanup

If you want to cleanup your machine again after playing with Windows Containers, use the following commands

vagrant destroy -f
vagrant box remove StefanScherer/windows_2019_docker
docker context rm 2019-box

More Repositories

1

dockerfiles-windows

Various Dockerfiles for Windows Containers
JavaScript
1,077
star
2

docker-windows-box

Various Vagrant envs with Windows 2019/10 and Docker, Swarm mode, LCOW, WSL2, ...
PowerShell
577
star
3

docker-cli-builder

Build Docker CLI for Windows
Dockerfile
246
star
4

adfs2

Multi Vagrant environment with Active Directory
PowerShell
138
star
5

swarm-monitor

Monitor a Docker Swarm with Blinkt! LED
JavaScript
49
star
6

dotfiles

My dotfiles for Mac / Linux boxes and WSL
Shell
37
star
7

dotfiles-windows

My "dotfiles" for Windows PowerShell, like dotfiles on unix
PowerShell
27
star
8

ghost-buster-docker

Run Ghost blog in Docker, and run Buster to deploy to GitHub pages
HTML
26
star
9

docker-at-home

Things I run at home on Raspberry Pi in Docker containers
Shell
25
star
10

windows-docker-workshop

Docker on Windows workshop
PowerShell
24
star
11

rpi-ubuntu

How to run Ubuntu with Docker on Raspberry Pi 3/4
23
star
12

basebox-slave

Build Vagrant baseboxes in vCloud with Packer, for vCloud, VMware and VirtualBox
Ruby
22
star
13

winspector

Inspect Windows Docker images to check sizes and base layers
JavaScript
20
star
14

docker-windows-azure

Deploy a Windows "Docker-Machine" on Azure
PowerShell
19
star
15

windows-docker-desktop-box

Vagrant box to test Docker Desktop with Linux/Windows containers
16
star
16

packer-builder

Packer builder for Vagrant boxes
Shell
15
star
17

stefanscherer.github.io

Just my techie notes.
HTML
14
star
18

pwned-passwords

Docker image to search for pwned passwords
Shell
13
star
19

choco-packer

Chocolatey 'packer' package
PowerShell
11
star
20

consul-agent

Consul MSI installer to install a Consul agent as a Windows service
PowerShell
11
star
21

vagrant-sandbox

My Vagrantfiles for sandbox tests
Ruby
11
star
22

pfsense-packer

Build a pfSense box with Packer
11
star
23

vagrant-vcloud-box

Ubuntu Desktop with preinstalled vagrant-vcloud plugin to work with vCloud
Shell
10
star
24

insider-docker-machine

Windows Server 2016 Insider with Docker (and LCOW)
PowerShell
10
star
25

rebase-docker-image

Rebase a dockerized Windows app to a newer Windows Docker base image.
JavaScript
10
star
26

windows10-docker-swarm

Windows 10 Insider + Docker swarm-mode
PowerShell
9
star
27

mac-dev-box

Mac OSX developer box the Vagrant way - now with Retina display
Shell
7
star
28

rpi-forked-daapd

Dockerized iTunes server for the Raspberry Pi
HTML
7
star
29

choco-docker-cli

Chocolatey package "docker-cli" for the Docker CLI
PowerShell
7
star
30

logbook

Installation logbooks of my machines
7
star
31

chocolateyfest-talk

Dockerfiles for the talk at Chocolatey Fest 2018
JavaScript
6
star
32

docker-rpi-traffic-light

Dockerized traffic light app running on a Raspberry Pi
Python
6
star
33

mint

Packer template for Linux Mint
Shell
5
star
34

choco-vmwareworkstation

Chocolatey packages for VMware Workstation
PowerShell
5
star
35

esxi-playground

ESXi 6.0 + Windows client as a playground
Shell
5
star
36

atmega32u4strip

Small LED strip project with Adafruit Atmega32u4 breakout board
Processing
5
star
37

node-rfc-docker

Example to use node-rfc in a Docker container
JavaScript
4
star
38

choco-docker-compose

Chocolatey 'docker-compose' package
PowerShell
4
star
39

choco-vagrant-vmware-utility

Chocolatey package for the Vagrant VMware Utility
PowerShell
4
star
40

azurepipelinetest

Test Azure Pipelines from a GitHub repo
Go
4
star
41

java-ide

Eclipse IDE for Java JEE Developers in an Ubuntu 12.04 LTS box
Shell
4
star
42

trinketstrip

A small LED project with Adafruit Trinket and NeoPixel strip
Arduino
4
star
43

gitrob-box

gitrob in a vagrant box
Shell
4
star
44

choco-archiver

Archiver tool as Chocolatey package - Easily create and extract .zip, .tar, .tar.gz, .tar.bz2, .tar.xz, .tar.lz4, .tar.sz, and .rar (extract-only) files with Go
PowerShell
4
star
45

fwe-fog

FWE FOG-Server configuration and scripts
PowerShell
4
star
46

sles-vm

Virtual machine templates for SuSE Enterprise Linux (SLES)
Shell
3
star
47

chocolatey-packages

My Chocolatey Package Repository
PowerShell
3
star
48

RFduino-guide

Quick starter guide for RFduino
3
star
49

packer-atlas-example

Automate building Vagrant Boxes with Packer in Atlas
Shell
3
star
50

circle2test

Test job workflows in CircleCI 2.0
Go
3
star
51

choco-manifest-tool

Chocolatey package for the manifest-tool
PowerShell
3
star
52

choco-docker-machine-vmwareworkstation

Chocolatey 'docker-machine-vmwareworkstation' package
PowerShell
3
star
53

azure-docker-swarm

Terraform template to spin up a Docker Swarm in Azure
HCL
3
star
54

appetizer

Chocolatey Fest appetizer app ๐Ÿซ
JavaScript
3
star
55

choco-docker-machine-vmware

Chocolatey package for the docker-machine-vmware plugin
PowerShell
2
star
56

choco-packer-post-processor-vagrant-vmware-ovf

Chocolatey 'packer-post-processor-vagrant-vmware-ovf' package
PowerShell
2
star
57

vcloud-scenarios

Some vagrant-vcloud scenarios
Ruby
2
star
58

image-builder-raspbian

Build and test Raspberry Pi SD card image in the cloud
Ruby
2
star
59

maketest

maketest
Makefile
2
star
60

talks

Slides for various presentations
HTML
2
star
61

rpi-kitematic

Run Kitematic in a Docker Container on your Raspbery Pi
Shell
1
star
62

caddy-builder

Fork of a caddy builder
Go
1
star
63

compose-builder

build docker-compose for ARM
1
star
64

iruby-box

IRuby in an Ubuntu box
Shell
1
star
65

lrtimelapse-box

Time lapse workflow on a Mac with Lightroom + LRTimelapse
Shell
1
star
66

test-vagrant-update

This repo is for testing a vagrant update 1.5.3 -> 1.6.2
PowerShell
1
star
67

rpi-gh

Raspberry Pi am Gymnasium Hรถchstadt
HTML
1
star
68

mac-docker-desktop-box

Vagrant box to test Docker Desktop for Mac in a Fusion VM
1
star
69

node-app-example

Test single exe Node.js application with AppVeyor
JavaScript
1
star
70

jenkins-debian-glue-box

Setup an Ubuntu box with jenkins-debian-glue
1
star
71

cups-cucumber-test

Test cups with vagrant-cucumber
Shell
1
star
72

win-getaddrinfo

Build a static Windows binary
C
1
star
73

arduino-ide

Arduino IDE running on Ubuntu 12.04
1
star
74

rpi-ledtest

Play with NeoPixel LED strips on Rapsberry Pi with Python
Python
1
star
75

tuxpaint-box

Tux Paint for kids is only a vagrant up away
1
star
76

choco-mkcert

Chocolatey package for the mkcert developer tool
PowerShell
1
star
77

win-patch-iojs

Windows tool to monkey-patch the iojs.exe to run in a Windows Docker container
C
1
star
78

appveyortest

Test AppVeyor Windows builder
1
star
79

serverspec-on-appveyor

Run serverspec tests on AppVeyor
Ruby
1
star
80

windows-docker-workshop-chat

Gitter chat during the Docker on Windows workshop
1
star
81

PiEmulator

Manual on how to set up a Raspberry Pi emulator
1
star
82

chat-example

Node.js chat-example with some Vagrant boxes
JavaScript
1
star
83

panamax-vcloud

Start a Panamax instance in VMware vCloud
Shell
1
star
84

travis-windows-test

Test TravisCI with Windows builder
1
star