145

I tried this on my Windows 10 machine:

Dockerfile:

From microsoft/nanoserver
CMD ["echo", "Hello World"]

PS

C:\FSD\Docker\Trial1> docker build -t lea/leatest .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM microsoft/nanoserver
latest: Pulling from microsoft/nanoserver
bce2fbc256ea: Pulling fs layer
58f68fa0ceda: Pulling fs layer
image operating system "windows" cannot be used on this platform
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lea A
  • 1,511
  • 2
  • 10
  • 9

5 Answers5

207

Your Docker host is configured to run Linux containers inside of a VM. To run Windows containers, you need to right click on the Docker icon in the system tray, and select "Switch to Windows containers…" in the Docker menu. This option is not available in "Home" versions of Windows. Documentation is available here.


A screenshot showing the location of the Docker icon in the taskbar

miken32
  • 42,008
  • 16
  • 111
  • 154
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • 2
    I am completely new to Docker, and for anyone likewise you need to find the Docker ** mini ** icon in the toolbar, right click and then select "Switch to Windows containers" in the Docker menu. Bear in mind that you need to reboot your workstation to complete the process. – arame3333 Nov 29 '17 at 10:19
  • 1
    For what it's worth I just switched to windows containers and I didn't need to reboot or anything. (Docker version 17.12.0-ce, build c97c6d6) – mat007 Feb 15 '18 at 14:30
  • Can you run both Windows and Linux containers at the same time on the same Windows 10 machine? – styfle Aug 10 '18 at 19:09
  • @styfle The above is a toggle, you can only do one at a time. There's been work to allow picking different runtimes so you could use both concurrently: https://blogs.msdn.microsoft.com/premier_developer/2018/04/20/running-docker-windows-and-linux-containers-simultaneously/ – BMitch Aug 10 '18 at 20:19
  • 1
    I have installed docker on Windows using `Docker toolbox`, I don't see docker icon in system tray. How can I do it? – paul Jan 29 '19 at 10:12
  • 1
    @paul docker toolbox uses docker machine to run Linux containers. Windows containers requires Docker for Windows, which requires newer Windows versions with HyperV enabled. – BMitch May 11 '19 at 12:20
  • Good answer. I wonder why such functionality has been buried into that popup menu and not available under Settings... – Ville Laitila Mar 15 '21 at 16:01
  • This isn't available on Windows 10 Home - it is grayed out. – Scotty H Apr 26 '21 at 16:11
  • 2
    After switching to Windows container, I had to run `Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All` on Windows PowerShell with elevated privileges – Agorreca Jul 12 '21 at 12:57
  • This requires Windows PRO or Windows Enterprise. – warchantua Oct 19 '21 at 14:50
  • 1
    @Agorreca: Thank you! I had done all of these steps and still could not figure out why I could not pull a Windows Docker image. Even though I am currently on Windows 11 Home, the toggle to switch between Linux and Windows containers is not grayed out for me and appears to work. So that was extra confusing. Thanks again for pointing this out – bmitc Jun 28 '22 at 02:44
  • @warchantua: Thank you as well for pointing out that this requires Windows Pro or Enterprise. I'm going to upgrade and hopefully this all works for me. – bmitc Jun 28 '22 at 02:44
49

You need to go to the Taskbar → right click the Docker icon → use option Switch to Windows containers...

Source https://docs.docker.com/docker-for-windows/

miken32
  • 42,008
  • 16
  • 111
  • 154
pbaranski
  • 22,778
  • 19
  • 100
  • 117
  • I have installed docker on Windows using `Docker toolbox`, I don't see docker icon in system tray. How can I do it? – paul Jan 29 '19 at 10:12
  • @paul I'm afraid that this solution is for Docker for Windows not the Toolbox. Just to add Docker for Windows is recommended software over Toolbox regarding interface (like mentioned Windows containers option) – pbaranski Jan 30 '19 at 11:24
  • `Docker for Windows` is preferred over `Docker Toolbox`? Why so? – paul Jan 31 '19 at 16:54
  • @paul Just relaying on docker staff response here: https://forums.docker.com/t/docker-for-windows-or-docker-toolbox/30387 , for contradiction I will add this resource: https://medium.com/short-stories-on-software/fixing-docker-to-run-smooth-on-windows-9e71dcc7c128 so you need to decide depending on your judgment :D – pbaranski Feb 01 '19 at 12:40
11

Switch to Windows Container needs to selected from docker icon running under hidden icon from the bottom right... The moment you switch from Linux to Windows or Windows to Linux, Docker daemon automatically restarts to consider switched container...


I would highly recommend you to view these 2 links to get more insight into how to create window containers:


I really found the content of these links very helpful to make a window container which is still being enhanced for the generic issue we are all are facing since support for window container is yet to mature like Linux containers!

Dženis H.
  • 7,284
  • 3
  • 25
  • 44
Abhishek Jain
  • 3,815
  • 2
  • 26
  • 26
8

microsoft/nanoserver is a windows native container image. So you cannot run this as linux containers run natively. It can only be run on windows 10 or windows server.

If you are in windows 10, you can switch to windows containers by selecting

switch to windows containers

prisar
  • 3,041
  • 2
  • 26
  • 27
  • It's a bit hidden as it's not in the docker desktop UI but your system task bar in the "hidden icons". Bring up running apps with the up arrow and right click the docker icon, then select that option. – Dmitri Larionov Apr 12 '22 at 20:43
0

Just to add to what the other's have answered before switching to windows containers, depending on how you installed docker ensure Microsoft Hyper-V containers are enabled.

Run as Administration on Powershell

Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All

Note: this will aslo restart your PC

Winter-py
  • 11
  • 1