Creating a docker image from an existing virtual machine

I need to create a basic docker image with CentOS and MySQL. But I already have such a VM (without dockers on it). How can I create an image of a basic docker from this existing virtual machine, and you are on another machine with a docker?

+5
source share
2 answers

While other commentators have correctly pointed out that importing a virtual machine into Docker is not designed to create images, this is possible and can provide you with a quick starting point for checking things out before you commit completely. To do this, you simply create the linux root file system (in your case: your CentOS VM) and transfer it to the docker import like this:

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

The Docker base image documentation contains more information and even script links for creating a CentOS base image.

+5
source

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

  • yum list is set
  • upload a basic docker image for centos X (or you can create one from scratch).
  • pass a subset of this output to a docker file with yum installed
  • create your image
  • If configurations / non-RPM installations are installed in your existing virtual machine, either rebuild them in the container, or in the worst case, share these
  • your MySQL is easier to manage; as long as the database folder / partition can be copied and distributed using dockers, you can install mysql and use this. We did this with postgres several times and hoping mysql would be just as clean.

The best part is that when you complete this exercise, you have a script that tells you how you created your image.

+4
source

Source: https://habr.com/ru/post/1242684/


All Articles