Can I run Docker in a Virtual Machine?
Asked Answered
B

6

63

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?

Banquet answered 27/9, 2016 at 8:52 Comment(2)
please can you provide more information, because it's like you tried to start on vm inside other vm.Gramercy
This is like InceptionAldebaran
L
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.

Leanneleanor answered 27/9, 2016 at 9:44 Comment(4)
parallels 11 / and virtual windows 7. not parallels 7.Banquet
thanks. and will try nested virtualization. i'm sorry i can't write english very well....Banquet
Disagree with "has much better host integration than Docker Machine". Lack of --network host is at lest one shortcoming in 'native' Docker for Mac/WindowsEnrobe
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.Piteous
B
64

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. :-)

Bedazzle answered 27/1, 2017 at 10:6 Comment(6)
"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?Mining
@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.Bedazzle
Not convincing.Mining
@MarinosAn I can't really understand, what should be convincing in it. This is a fact.Bedazzle
@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...Spelter
@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).Bedazzle
L
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.

Leanneleanor answered 27/9, 2016 at 9:44 Comment(4)
parallels 11 / and virtual windows 7. not parallels 7.Banquet
thanks. and will try nested virtualization. i'm sorry i can't write english very well....Banquet
Disagree with "has much better host integration than Docker Machine". Lack of --network host is at lest one shortcoming in 'native' Docker for Mac/WindowsEnrobe
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.Piteous
G
23

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.

Glyco answered 27/5, 2020 at 11:59 Comment(2)
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.Asco
Sucks that for Ryzen you need VM configuration 10 which requires Windows ServerBombazine
D
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.

Dunford answered 27/1, 2022 at 17:10 Comment(8)
Interesting. Never heard of this. It does in fact seem to say that.Gurl
I tried asking about this on the community forums and was told to ask Docker directly. I tried that, but haven't gotten a response yet.Dunford
Seem like docker updated this paragraph. It requires a Docker business license but it's not forbidden in general.Volumeter
They have indeed updated it now; thanks for pointing that out!Dunford
@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 4.1.b)Swartz
@Dunford Could you please offer a link to the question you asked Docker directly?Swartz
@Swartz 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.Dunford
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.Roundtheclock
O
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.

Oyer answered 3/1, 2021 at 2:54 Comment(0)
D
-2

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.

Damascene answered 23/6, 2022 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.