59

I tried to run Docker on a virtual machine.

Host : MacBook 
VM : Parallels Windows 7

And error occurs:

enter image description here

Is it possible?

John Wiseman
  • 3,081
  • 1
  • 22
  • 31
shkim
  • 793
  • 1
  • 5
  • 14

6 Answers6

62

If the VM is a Linux, you can do this without any problem - on Linux, the Docker is essentially a well-worked chroot. Thus, the Linux docker is not virtualization.

In the case of Windows, it is not so easy. Windows Docker internally uses Hyper-V to emulate the containers. Which means that you can only run, if you can use nested virtualization:

  1. On your host machine runs a Windows VM
  2. Inside your Windows VM, runs a HyperV
  3. HyperV is managed by the docker installed on your virtual Windows.

I tried qemu/kvm, virtualbox and vmware player. I configured them deeply and strongly, I've hacked them, I did every possible to do. Only the last worked (VMWare).

There are significant speed costs, but it may be useful for development on Linux, and then trial-test on Windows configurations.

You will need a lot of ram. At least 16G. 32G is better. A relative useful configuration would be:

  • 32GB physical RAM for the physical host
  • 12GB virtual RAM for the Windows VM running on it
  • 8GB virtual RAM inside the Windows VM for the HyperV Linux host.

Sometimes it will be a little bit buggy, but only your HyperV will crash out, your virtual Win, or your host machine won't. It is okay for testing a docker container on a Windows machine, what you've developed on a Linux. Don't create mission critical servers on this way. :-)

famousgarkin
  • 13,687
  • 5
  • 58
  • 74
peterh
  • 11,875
  • 18
  • 85
  • 108
  • "If the VM is a Linux, you can do this without any problem". Do you mean there is no performance cost? If so, is it possible that you provide some links that explain this? – Marinos An Nov 07 '17 at 11:09
  • 1
    @MarinosAn There is no performance cost from the virtualization, because the linux docker is essentially a well-worked chroot. On Windows, docker is a hyper virtual machine, running linux, running Linux docker. – peterh Nov 07 '17 at 11:28
  • 1
    Not convincing. – Marinos An Nov 07 '17 at 11:56
  • 11
    @MarinosAn I can't really understand, what should be convincing in it. This is a fact. – peterh Nov 07 '17 at 11:58
  • 2
    @MarinosAn It is convincing cause windows sucks :) Windows itself needs a lot of resources and if you manage to run vm's in it you are increasing your costs... – Amir Hossein Baghernezad Dec 14 '17 at 17:56
  • @TechJS Yeah :-) Furthermore, nested virtualization is a hard thingy, it is working only in a few, tricky combinations. Since docker uses hyperv, the internal virtualisation should be hyperv. The external virtualization worked by me only with VMWare (also VMWare Player is okay). I tried virtualbox, qemu and vmware. If the host-host machine is a Windows, then maybe a HyperV on HyperV solution could also work (I didn't try that). – peterh Jan 15 '18 at 16:09
  • 1
    @Webman Sorry I can't really understand your question, but posting it as a question (clicking the "Ask Question") button could get you probably more help. – peterh Sep 09 '18 at 19:41
31

You're using Docker Machine in your Windows VM, which is actually going to create a Linux VM inside the Windows VM on your Mac. You can do that, but you need to enable nested virtualization - which I'm not sure you can do in Parallels 7.

Instead you can run Docker Machine on the Mac directly and use Parallels to create the Linux VM - which means Docker is running in a Linux VM on your Mac, and you don't need nested virtualization.

Or preferably use Docker for Mac if your OS supports it, it's the latest product and has much better host integration than Docker Machine.

Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
  • parallels 11 / and virtual windows 7. not parallels 7. – shkim Sep 29 '16 at 05:46
  • thanks. and will try nested virtualization. i'm sorry i can't write english very well.... – shkim Sep 29 '16 at 05:47
  • Disagree with "has much better host integration than Docker Machine". Lack of `--network host` is at lest one shortcoming in 'native' Docker for Mac/Windows – goofology Sep 05 '19 at 03:25
  • Note also that nested virtualization is something that also needs to be supported by the CPU and not only by the OS that is the host. – rbaleksandar Apr 04 '20 at 09:41
17

If you would be using Windows 10/11 Pro or Enterprise and Hyper-V, then all you must do is to enable nested virtualization. On your host, just run (with your guest off):

> Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true

Now you can start your guest and run Docker Desktop as normal.

Oskar
  • 1,996
  • 1
  • 22
  • 39
  • 1
    After installing Docker and WSL 2, this was the last command I was missing for Docker to run on my VM. Thank you. I have Windows 11 Pro, and a virtual machine on Hyper-V with also Windows 11 installed. In my case, the name of my virtual machine had spaces so I used double quotes for the name. I opened a power shell window as admin and ran this: Set-VMProcessor -VMName "My Machine Name" -ExposeVirtualizationExtensions $true After that, I was able to run Docker on that VM. – Jelgab May 31 '23 at 22:52
6

According to Docker's terms I don't think it's allowed. Section 4.1(b)(vii) says you shall not "use the Service on virtual machines." For clarification, "'Service' refers to the applications, software (including any Open Source Software), products and services provided by Docker, including any beta or trial versions."

If I am reading this right, that means it's illegal to run Docker on any VM.

nullromo
  • 2,165
  • 2
  • 18
  • 39
  • 1
    Interesting. Never heard of this. It does in fact seem to say that. – Brooks Feb 11 '22 at 22:45
  • 1
    I tried asking about this [on the community forums](https://forums.docker.com/t/is-docker-allowed-on-virtual-machines/120441) and was told to ask Docker directly. I tried that, but haven't gotten a response yet. – nullromo Feb 14 '22 at 16:53
  • 1
    Seem like docker updated this paragraph. It requires a Docker business license but it's not forbidden in general. – GeofoxCoding Dec 16 '22 at 05:50
  • They have indeed updated it now; thanks for pointing that out! – nullromo Dec 17 '22 at 07:16
  • @GeofoxCoding: If (as stated in the license) it requires a Docker business license then what does the phrase "you shall not" mean? Doesn't "you shall not" mean the same as "it is forbidden" in legal terms? (See [Docker Subscription Service Agreement](https://www.docker.com/legal/docker-subscription-service-agreement/) 4.1.b) – wolfrevo Mar 04 '23 at 07:53
  • 1
    @nullromo Could you please offer a link to the question you asked Docker directly? – wolfrevo Mar 04 '23 at 07:58
  • @wolfrevo I sent the question to them using their e-mail support. I got a confirmation e-mail saying they would get back to me, but that was over a year ago and they never replied. I believe the phrase “you shall not [do something]” here means that if you do that thing, then you have violated the terms. – nullromo Mar 05 '23 at 01:19
  • as of July 2023, that phrase is not found in the original link, but there is a related phrase which is in short quite flexible and reflects the status-quo: Customer acknowledges that while Customer is permitted to use Docker Desktop on a virtual machine, as of the Effective Date of this Agreement, such use is an unsupported configuration. – YaP Jul 10 '23 at 19:00
2

Worked perfectly fine. Base OS win 10 pro with VirtualBox Version: 6.1 and vagrant with ubuntu 20.04. Using vagrant box follow docker instructions. With vagrant public network no need for port forwarding all apps were accessible.

citynorman
  • 4,918
  • 3
  • 38
  • 39
-1

Previous persons comment is very concerning considering on Windows and Mac you run docker inside a virtual machine lul. Windows uses WSL2 and Mac uses an arm linux machine to manage its docker.

Also, you can run docker in a vm, but it must be linuxOS vm as windows 7 does not support docker.