29

I'm running docker for mac and want to start up a windows container. From what I see this should work via a virtual machine. But I'm unclear where to find out how to get it to work? Or does it only work for linux containers? Thanks in advance!

docker build nanoserver/
Sending build context to Docker daemon   2.56kB
Step 1/6 : FROM microsoft/nanoserver:10.0.14393.1480
10.0.14393.1480: Pulling from microsoft/nanoserver
bce2fbc256ea: Pulling fs layer 
baa0507b781f: Pulling fs layer 
image operating system "windows" cannot be used on this platform
Chip
  • 1,439
  • 3
  • 15
  • 29

3 Answers3

16

I know I am late to the party but as of 2021, this is the easiest setup to get a windows container running on macOS:

https://github.com/StefanScherer/windows-docker-machine

  1. Install vagrant and virtual box
  2. Clone the repository above and change directory into it
  3. vagrant up --provider virtualbox 2019-box
  4. docker context use 2019-box

I followed this setup and I could use the following windows image

mcr.microsoft.com/windows/servercore:ltsc2019

Please note that the windows version of your host must match the container image. This is mentioned here: https://hub.docker.com/_/microsoft-windows

Windows requires the host OS version to match the container OS version. If you want to run a container based on a newer Windows build, make sure you have an equivalent host build.

binford
  • 1,655
  • 1
  • 18
  • 36
  • I tried this just now and got a vagrant error. I opened an issue in the repo, but have no idea if that will elicit a prompt response or not. – szeitlin May 06 '22 at 22:59
  • 1
    This is [the issue](https://github.com/StefanScherer/windows-docker-machine/issues/83) @szeitlin is referring to. Apparently, it can be fixed by downgrading vagrant. – binford Dec 08 '22 at 12:55
  • So if I understand correctly, your suggestion is to run a Windows VM then run a docker container in that VM. Is that right? – Code-Apprentice Jun 20 '23 at 18:18
  • 1
    @Code-Apprentice Yes. If you want to run a Windows container on macOS you have no other choice. Docker doesn’t provide portability across operating systems. This is a key difference to VMs. This is explained in-depth [here](https://www.weave.works/blog/a-practical-guide-to-choosing-between-docker-containers-and-vms). – binford Jun 21 '23 at 08:44
8

See this link: https://forums.docker.com/t/how-do-i-start-a-windows-docker-container-on-my-mac-os-x/12953/2

Text if you can't follow the link:

On OS X, get VirtualBox. Get Windows Server 2016 Tech Preview 5 ISO167 (free download from Microsoft) Create WS 2016 TP5 VM in virtualbox Run this206 in the new VM Now you can run Windows Containers in the VM. To make the setup a little easier to use, see this: https://forums.docker.com/t/windows-server-2016-tp5-docker-server-remote-management/10315/5317

Alan H
  • 3,021
  • 4
  • 25
  • 24
Chris
  • 377
  • 1
  • 7
  • 3
    Docker has added some labs that show all the ways to setup to use Windows Containers. The only way to do it on OSX is in a VM or using a cloud provider like Azure: https://github.com/docker/labs/blob/master/windows/windows-containers/Setup.md – Mano Marks Jul 28 '17 at 20:43
  • 17
    Is this still the answer, for Aug 2018? Or have things changed in a year (for the better) ? – Pure.Krome Aug 03 '18 at 09:24
  • Yes I want to do this also, it seems that this is for Docker Toolbox and is not relevant with the new Docker Desktop. I found this post https://www.clearpeople.com/insights/blog/2018/june/sitecore-demo-in-a-docker-container which suggests there is a "Windows Container Mode" I can't find anything on it or how to set it. – Lenny D Feb 12 '19 at 12:48
  • I created this question https://stackoverflow.com/questions/54650721/can-i-run-windows-containers-on-docker-desktop-for-mac lets see – Lenny D Feb 12 '19 at 13:02
  • 1
    @LennyD "Windows Container Mode" is only available on Docker for Windows, where you can easily switch between Windows and Linux containers. Unfortunately there is no equivalent on OSX – Shagglez May 03 '19 at 08:47
  • 1
    As of 2021, there is an easier solution, see [my answer](https://stackoverflow.com/a/68908748/517173) in the duplicate question. – binford Aug 27 '21 at 09:58
  • VirtualBox 6.1.30 (released November 22 2021) - macOS host: show message indicating the unsupported CPU on M1 based Macs and abort installation – Míng Jan 14 '22 at 10:16
-1

You could also install Bootcamp on your machine which allows you to dual boot your computer between OS X and Windows 10. You could then use the full power of your hardware dedicated to Windows and docker instead of virtualization.

Additionally, you can make the use of VMWare Fusion for Mac OS or Parallels, which allow you to ALSO access the dual boot windows partition from within the Mac OS for maximum flexibility. During installation make sure you do not create a Virtual Machine drive, but instead access the bootcamp partition directly.