Build Virtual Machine Image from Dockerfile or Docker image
Build Virtual Machine Image from Dockerfile or Docker image
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
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.
Working and tested:
Unsupported:
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.
sudo or root privileges are required for d2vm to performs operations that require root-level permissions, in particular:
docker commands, which require root-level permissions by defaultNote: 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.
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"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:latestbrew install linka-cloud/tap/d2vmDownload 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).
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/Clone the git repository:
git clone https://github.com/linka-cloud/d2vm && cd d2vmInstall using the make, docker and the Go tool chain:
make installThe d2vm binary is installed in the $GOBIN directory.
which d2vm
/go/bin/d2vmThe d2vm program supports shell completion for bash, zsh and fish.
It can be enabled by running the following command:
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.
The example directory contains very minimalistic examples:
cd examplesubuntu.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.
d2vm build --help…sudo d2vm build -p MyP4Ssw0rd -f ubuntu.Dockerfile -o ubuntu.qcow2 .Or if you want to create a VirtualBox image:
sudo d2vm build -p MyP4Ssw0rd -f ubuntu.Dockerfile -o ubuntu.vdi .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.
A complete example setting up a ZSH workstation is available in the examples/full directory.
You can find the Dockerfiles used to install the Kernel in the templates directory.
ENTRYPOINT CMD WORKDIR and ENV instructions ?ENV variables into .bashrc or other service environment file ?The run commands are adapted from linuxkit.
No open issues yet, or sync has not completed.