Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create docker image from existing virtual machine

I need to create docker base image with CentOS and MySQL. But I already have such VM (without docker on it). How can I create base docker image from this existing VM and use it on another machine with docker?

like image 348
user1590561 Avatar asked Feb 10 '16 05:02

user1590561


2 Answers

While the other commenters have pointed out correctly that importing a VM into Docker is not the intended way to create images, it is possible and can provide you with a fast starting point to test things before you fully commit. To do this, you simply provision a linux root file system (in your case: your CentOS VM) and stream it into docker import like so:

tar -cC [folder containing provisioned root fs] . | docker import - [image name]

Docker's base image documentation has more info and even links to a script to create a CentOS base image.

like image 135
stepf Avatar answered Oct 24 '22 08:10

stepf


I think you misunderstand what docker does (or I misunderstand your question). Docker is not a VM provider; it's a container management mechanism based on libcontainer. In your case, I would do something like

  • yum list installed
  • download a base docker image for centos version X (or you could create one from scratch)
  • pipe a subset of this output into a Dockerfile with yum install
  • create your image
  • if there are configs/non-RPM installs in your existing VM, either rebuild these in the container or worst case, share these
  • your MySQL is easier to manage; as long as the database folder/partition can be copied & shared with docker, you may be able to install mysql and use this. Have done this with postgres a number of times and hoping mysql is similarly clean.

The nice thing is once you go through this exercise, you have a script that tells you exactly how you created your image.

like image 29
Stevens-fan Avatar answered Oct 24 '22 07:10

Stevens-fan