Create docker image from existing virtual machine

跟風遠走 提交于 2020-01-28 02:19:28

问题


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 you it on another machine with docker?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/35307595/create-docker-image-from-existing-virtual-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!