C2V: My thoughts on ‘Docker Container to VM’ conversion

The truth is that big part of IT population does not clearly understand what Docker is.

 

I recently got a question from one of my customers, if I can perform conversion of a Docker container to a full VM. “We developed an app in Container, now we want to run it on separate VM” – he told.
I tried to explain some things, and tried to understand the reasoning behind that request, but, eventually, customer is customer and if customer asks, we need to find a solution.

To be honest, I was interested myself, if such a C2V is even possible. What tools can be used to do that?
You could think “Well, it is Linux container, so why not to install SSH inside it and just convert it using VMware converter.” I tried it actually, and of course, as I was expecting it did not work. The reason is simple: “Boot disk not found”.
If you are surprised at this point, it means you do not clearly understand how Docker works.

Some theory: Docker is a Container technology, It does not run a full blown OS inside a container, it runs only the processes application needs.
In simple words:

  • Docker container does not have its own disks.
  • Docker container does not have boot partition with ‘Boot loader’ inside (because it never boots)
  • Docker container does not even have INIT process. The PID 1 in docker container is your own application.

OK, so what should we do, if our customer demands us to convert it to a VM?
The answer is simple, try to explain to customer, that it is not possible. Propose other options. I can even suggest some.

  1. Nice one: Build new VM and deploy the application inside.
  2. Strange one: Convert the whole Docker host together with Docker container which hosts the application.
  3. The Extra complex one (this is theory only, I haven’t tested it):
    1. Build an image file with dd command
    2. Create partition table in image file and write an MBR on it.
    3. Format partitions in image file.
    4. Mount image file and rsync files from Docker container to the filesystem inside.
    5. Mount system partitions to copied partition ( /proc, /sys, /dev, etc)
    6. chroot into mounted image.
      1. download and install Kernel and Bootloader (it may be needed to compile Kernel).
      2. create /etc/fstab file.
      3. create /etc/resolv.conf
    7. Convert image file to .vmdk using qemu-img.
    8. Create VM and configure it to use the .vmdk file from previous step.

Option 3 is basically same as building new OS and copying the app. You just build OS with your own hands (reminds me of Gentoo).  It is just an interesting and complex solution which worth to be mentioned.

 

In conclusion I want to say, Docker has its own purpose, and if your plan is to run your application in a VM, consider migration plan in advance.

The following two tabs change content below.
Aram Avetisyan is an IT specialist with more than 15 years experience. He has rich background in various IT related fields like Cloud, Virtualization, SDN, Disaster Recovery, and so on. He holds several industry level certifications including but not limited to VCIX6-DCV, VCIX6-NV, VCAP-CIA. As VCI Aram is delivering VMware authorised courses. For his contribution to the community, he was recognised as vEXPERT in years 2014, 2015 and 2016.

About Aram Avetisyan

Aram Avetisyan is an IT specialist with more than 15 years experience. He has rich background in various IT related fields like Cloud, Virtualization, SDN, Disaster Recovery, and so on. He holds several industry level certifications including but not limited to VCIX6-DCV, VCIX6-NV, VCAP-CIA. As VCI Aram is delivering VMware authorised courses. For his contribution to the community, he was recognised as vEXPERT in years 2014, 2015 and 2016.

Bookmark the permalink.

7 Comments

  1. Check “project atomic” and its result, cloud version of fedora 21. That should fully cover your customers needs.

    • Hello Fana,

      Thanks for comment.
      Indeed, Project Atomic looks promising as a Docker management system. Yes, it can automatically build VM with Docker inside.
      But it still does not solve the problem I try to describe here, problem of converting Docker containers to full blown VMs.

  2. Well, you simply cant convert container (which is basically 1 process encapsulated with its filespace) to operating system. What you can do is to give it minimal possible OS to run the container. What I was trying to say before: why would you create your own operating system (option 3 in a blog post) when there is someone who already did that job. 😉 Atomic or coreos are fine for this purpose.

    • Hi again Franta,

      I totally agree with you, that’s why Option 3 is called “the extra complex one” It completely makes no seance to recreate OS in that way, but it is still an option

      what comes to creating minimal OS to run container: Sometimes you just want to run an application on OS directly, and it makes no sense to run even minimal OS, and then run container on it. And that’s when Option 1 comes in.

      What I wanted to say is that there is no definitive way or tool to convert Docker container, but there are tons of ways how to get your app to run in VM. and those are not limited to 3 options I mentioned. These 3 options are just examples to kick of the imagination.

      Thanks again for sharing your thought on this.

  3. Is it possible to convert a VMware VM running my Tomcat application to convert in to Docker instance. I have 10 legacy applications running on different VM’s, I want to run them as Docker instance. Is there tool to do V2C?

    • Hello Pradeep,
      Thanks very much for question.
      I don’t think there is such a tool, even more, I honestly don’t think it is a good idea to convert existing VM. It will for sure contain a lot of unneeded things.
      I think it would be better to start with clean Docker OS image and deploy your application on it. Once you will have it done, you can export it as a ‘Docker image’, and then re-deploy it as many times as you need.

  4. Pingback: Thevirtualist: C2V & thoughts on ‘Docker Container to VM’ conversion - How2VM

Comments are closed