react 前端框架如何驱动企业数字化转型与创新发展
670
2022-10-30
从Dockerfiles构建并运行微小的vms,小巧时尚
slim will build a micro-vm from a Dockerfile. Slim works by building and extracting a rootfs from a Dockerfile, and then merging that filesystem with a small minimal kernel that runs in RAM.
This results in a real VM that can boot instantly, while using very limited resources. If done properly, slim can allow you to design and build immutable unikernels for running services, or build tiny and embedded development environments.
Using slim
Build a micro-vm
Create a micro-vm from a Dockerfile. Use build command with a directory containing a Dockerfile.
$ slim build images/alpine3.8-simple
This will add a bootable iso in the slim registry. See example Dockerfile.
slim build will use your default provider unless the -p flag is specified (ie -p hyperkit).
Listing micro-vm images
See a list of micro-vm images on your machine.
$ slim images
Running a micro-vm
Provision a new instance of the given micro-vm image as a virtual machine.
Slim currently supports Virtualbox, KVM, and hyperkit (MacOS only) as providers for running VMs. Slim will discover all available providers, defaulting to virtualbox, if more than one provider is available. The -p flag can be used to force Slim to use a specific provider.
Using hyperkit (requires sudo):
$ slim run micro1 alpine3.8-simple -p hyperkit
Using virtualbox:
$ slim run micro2 alpine3.8-simple
VirtualBox will run the micro-vm instance as an attached iso loaded into a cdrom, and boot up the iso in seconds.
For convenience, a ssh connection command is provided at the end of the command, allowing easy access into the machine:
Example: ssh -i /Users/cjparnin/.slim/baker_rsa root@127.0.0.1 -p 2008 -o StrictHostKeyChecking=no
Advanced Features
Build formats
Slim supports building multiple image formats, but by default will only build the image required for the given provider. The -f flag can be used to specify any additional image formats that should be built, which will be stored in the registry directory for that image. The currently supported formats and their corresponding providers are:
| raw | iso | qcow2 |
---|---|---|---|
kvm | ✓ | ✓ | ✓ |
hyperkit | ✓ | ✓ | |
virtualbox | ✓ | ✓ |
The raw format signifies an unbundled ramfs archive and kernel.
Example: running slim build images/alpine3.8-simple -p kvm -f qcow2 will build a raw image (KVM's default image format), as well as a qcow2 image.
Shared Folders
Slim will automatically mount / at /host and cwd (ie the directory where you run the slim run command) at /slim within the VM. This automounting can be disabled by passing the --sync=no option in the slim run command. The example alpine3.8-simple and ubuntu16.04-simple images illustrate how to support mounting within the image, and is documented here.
Build and run parameters
Using slim build
Managing vms and images
You can get a list of vms with slim vms.Force shutdown of a vm. slim stop micro1 (Note: for hyperkit, this will be the equivalent of delete.)You can delete a specific vm called "v0" with slim delete vm v0You can delete a specific image in registry called "ubuntu" with slim delete image ubuntuYou can clean out the entire image registry with slim clean.
Extending base images (experimental)
Instead of having to copy and extend an existing Dockerfile, we're experimenting with a reuse pattern that lets you reference an existing base image hosted in a git repository, and extend it by passing in build arguments. For example, by defining this in an info.yml, you could extend the base alpine3.9 image with ansible and runc.
description: A simple configuration server with ansible and runc (for running containers).base_repository: https://github.com/ottomatica/slimbase_directory: images/alpine3.9-simplebase_args: PKGS: runc ansible
Example micro-vms
A collection of micro-vms can be found here, including ubuntu base images, jenkins, kubenetes, and more: https://github.com/ottomatica/slim-images
Installing slim
Simply clone this repo and run:
npm installnpm link
Unfortunately, due to the experimental nature, there are a few system dependencies you must also install:
docker, for building and extracting the kernel and filesystem.cdrtools: brew install cdrtools, for building the micro-vm iso.
To boot and run the image, you also need a hypervisor:
VirtualBox, kvm on Linux, or hyperkit on macOS.
For kvm, you can install the following dependencies for ubuntu:
sudo apt-get install qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker mkisofs
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~