1.7.1 • Published 2 years ago
@unhand/vmenv v1.7.1
VmEnv
A wrapper for nerdctl
Install
macOS
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install lima
Windows WSL2
$ wsl -d Ubuntu-20.04
$ wsl -s Ubuntu-20.04
$ useradd -r -m -s vmenv && exit
$ wsl -u vmenv
Demo
import { VmEnv } from "./vmenv";
const vm = new VmEnv();
vm.init();
const container = vm.run("run -d hello-world");
const containerId = container.stdout;
vm.run("ps -a");
vm.run(`stop ${containerId}`);
vm.run(`rm ${containerId}`);
vm.run("ps -a");
const images = vm.run("images");
console.log(
images.stdout
.split("\n")[1]
.split(" ")
.filter((o: string) => !!o)
.map((o: string) => o.trim())
);
output:
vmenv run: run -d hello-world
98d1b4786714268eea208922f57279470f9f0467ee6bf8b075890b769069e765
vmenv run: ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
98d1b4786714 docker.io/library/hello-world:latest "/hello" Less than a second ago Exited (0) Less than a second ago hello-world-98d1b
vmenv run: stop 98d1b4786714268eea208922f57279470f9f0467ee6bf8b075890b769069e765
98d1b4786714268eea208922f57279470f9f0467ee6bf8b075890b769069e765
vmenv run: rm 98d1b4786714268eea208922f57279470f9f0467ee6bf8b075890b769069e765
98d1b4786714268eea208922f57279470f9f0467ee6bf8b075890b769069e765
vmenv run: ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
vmenv run: images
REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE
hello-world latest bfea6278a0a2 26 minutes ago linux/arm64/v8 16.0 KiB 7.6 KiB
[
'hello-world',
'latest',
'bfea6278a0a2',
'26 minutes ago',
'linux/arm64/v8',
'16.0 KiB',
'7.6 KiB'
]