百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

d2vm

> DevOps
开源

从 Dockerfile 或 Docker 镜像构建虚拟机镜像

371 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

从 Dockerfile 或 Docker 镜像构建虚拟机镜像

d2vm (Docker to Virtual Machine)

Build virtual machine image from Docker images

The project is heavily inspired by the article and the work done by iximiuz on docker-to-linux.

Many thanks to him.

Status: alpha

Supported Environments:

Only building Linux Virtual Machine images is supported.

Starting from v0.1.0, d2vm automatically run build and convert commands inside Docker when not running on linux or when running without root privileges.

Note: windows should be working, but is totally untested.

Supported VM Linux distributions:

Working and tested:

  • Ubuntu (18.04+) Luks support is available only on Ubuntu 20.04+
  • Debian (stretch+) Luks support is available only on Debian buster+
  • Alpine
  • CentOS (8+)
  • Rocky Linux
  • AlmaLinux

Unsupported:

  • RHEL

The program uses the /etc/os-release file to discover the Linux distribution and install the Kernel, if the file is missing, the build cannot succeed.

Obviously, Distroless images are not supported.

Prerequisites

osx

  • Docker
  • QEMU (optional)
  • VirtualBox (optional)

Linux

  • Docker
  • util-linux
  • udev
  • parted
  • e2fsprogs
  • dosfstools (when using fat32)
  • mount
  • tar
  • extlinux (when using syslinux)
  • qemu-utils
  • cryptsetup (when using LUKS)
  • QEMU (optional)
  • VirtualBox (optional)

sudo or root privileges

sudo or root privileges are required for d2vm to performs operations that require root-level permissions, in particular:

  • mounting disk images and loopback devices requires elevated privileges
  • invoke docker commands, which require root-level permissions by default

Getting started

Install

With Docker

Note: this will only work if both the source context (and Dockerfile) and the output directory are somewhere inside the directory where you run the command.

bash
docker pull linkacloud/d2vm:latest
alias d2vm="docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock --privileged -v \$PWD:/d2vm -w /d2vm linkacloud/d2vm:latest"
bash
which d2vm

d2vm: aliased to docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock --privileged -v $PWD:/d2vm -w /d2vm linkacloud/d2vm:latest

With Homebrew

bash
brew install linka-cloud/tap/d2vm

From release

Download the latest release for your platform from the release page.

Extract the tarball, then move the extracted d2vm binary to somewhere in your $PATH (/usr/local/bin for most users).

bash
VERSION=$(git ls-remote --tags https://github.com/linka-cloud/d2vm |cut -d'/' -f 3|tail -n 1)
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$([ "$(uname -m)" = "x86_64" ] && echo "amd64" || echo "arm64")
curl -sL "https://github.com/linka-cloud/d2vm/releases/download/${VERSION}/d2vm_${VERSION}_${OS}_${ARCH}.tar.gz" | tar -xvz d2vm
sudo mv d2vm /usr/local/bin/

From source

Clone the git repository:

bash
git clone https://github.com/linka-cloud/d2vm && cd d2vm

Install using the make, docker and the Go tool chain:

bash
make install

The d2vm binary is installed in the $GOBIN directory.

bash
which d2vm

/go/bin/d2vm

Generate shell completion

The d2vm program supports shell completion for bash, zsh and fish.

It can be enabled by running the following command:

bash
source .
[    3.838984] systemd[1]: Created slice system-getty.slice.
[  OK  ] Created slice system-getty.slice.
[    3.845038] systemd[1]: Created slice system-modprobe.slice.
[  OK  ] Created slice system-modprobe.slice.
[    3.852054] systemd[1]: Created slice system-serial\x2dgetty.slice.
[  OK  ] Created slice system-serial\x2dgetty.slice.

...

Ubuntu 20.04.4 LTS localhost ttyS0

localhost login:

Log in using the root user and the password configured at build time.

…

Type poweroff to shut down the vm.

Building a VM Image from a Dockerfile

The example directory contains very minimalistic examples:

bash
cd examples

ubuntu.Dockerfile :

dockerfile
FROM ubuntu

RUN apt update && apt install -y openssh-server && \
    echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

Build the vm image:

The build command take most of its flags and arguments from the docker build command.

bash
d2vm build --help
…
bash
sudo d2vm build -p MyP4Ssw0rd -f ubuntu.Dockerfile -o ubuntu.qcow2 .

Or if you want to create a VirtualBox image:

bash
sudo d2vm build -p MyP4Ssw0rd -f ubuntu.Dockerfile -o ubuntu.vdi .

KubeVirt Container Disk Images

Using the --tag flag with the build and convert commands, you can create a Container Disk Image for KubeVirt.

The --push flag will push the image to the registry.

Complete example

A complete example setting up a ZSH workstation is available in the examples/full directory.

Internal Dockerfile templates

You can find the Dockerfiles used to install the Kernel in the templates directory.

TODO / Questions:

  • Create service from ENTRYPOINT CMD WORKDIR and ENV instructions ?
  • Inject Image ENV variables into .bashrc or other service environment file ?
  • Use image layers to create rootfs instead of container ?

Acknowledgments

The run commands are adapted from linuxkit.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gobuildbuildhaclouddocker

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理