vmware vctl 容器技术

第一次使用

这是一个在后台运行的运行时守护进程。必须先启动 containerd 守护进程,然后才能运行任何与容器相关的操作。要启动该守护进程,请使用 vctl system start 命令,要停止该守护进程,请使用 vctl system stop 命令

PS C:\Users\admin> vctl pull helloworld
FATAL Container engine is not running. Run 'vctl system start' to launch it

PS C:\Users\admin> $Env:http_proxy="http://127.0.0.1:7890";$Env:https_proxy="http://127.0.0.1:7890"

PS C:\Users\admin> vctl system start
Downloading 1 files...
Downloading [crx.vmdk 99.03%]
Finished crx.vmdk 100.00%
1 files successfully downloaded.
Preparing storage...
Container storage has been prepared successfully under C:\Users\admin\.vctl\storage
Preparing container network...
Container network has been prepared successfully using vmnet: vmnet8
Launching container runtime...
Container runtime has been started.

PS C:\Users\admin> vctl pull hello-world
INFO Pulling from index.docker.io/library/hello-world:latest
───                                                                                ──────   ────────
REF                                                                                STATUS   PROGRESS
───                                                                                ──────   ────────
index-sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf      Done     100% (2562/2562)
manifest-sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4   Done     100% (525/525)
layer-sha256:2db29710123e3e53a794f2694094b9b4338aa9ee5c40b930cb8063a1be392c54      Done     100% (2479/2479)
config-sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412     Done     100% (1469/1469)
INFO Unpacking hello-world:latest...
INFO done

PS C:\Users\admin> vctl run hello-world
INFO container hello-world-04a3 started

Hello from Docker!
This message shows that your installation appears to be working correctly.

PS C:\Users\admin> vctl run --name mydb -m 2048 -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 mysql
INFO container mydb started
2021-10-08T02:21:05.113739Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.26) initializing of server in progress as process 42
2021-10-08 02:21:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.
2021-10-08 02:21:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-10-08 02:21:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.26-1debian10 started.

vctl技术分析

vctl采用的是crx虚拟机

Untitled

PS C:\Users\admin> vctl ps
────   ─────          ───────                   ──              ─────           ──────    ─────────────
NAME   IMAGE          COMMAND                   IP              PORTS           STATUS    CREATION TIME
────   ─────          ───────                   ──              ─────           ──────    ─────────────
mydb   mysql:latest   docker-entrypoint.sh...   192.168.5.130   3306:3306/tcp   running   2021-10-08T10:20:59+08:00
PS C:\Users\admin> vctl execvm --sh -c mydb
sh-4.4#

PS C:\Users\admin> vctl stop mydb
INFO container mydb has been stopped

#查看虚拟机路径
PS C:\Users\admin> vctl describe mydb
Name:                       mydb
Status:                     running
Command:                    docker-entrypoint.sh mysqld
Container rootfs in host:   C:\Users\admin\.vctl\storage\containerd\root\io.containerd.snapshotter.v1.native\snapshots\16
IP address:                 192.168.5.130
Creation time:              2021-10-08T10:26:28+08:00
Image name:                 mysql:latest
Image size:                 143.6 MiB
Host virtual machine:       C:\Users\admin\.vctl\.r\vms\mydb\mydb.vmx
Container rootfs in VM:     /.containers/mydb
Access in host VM:          vctl execvm --sh -c mydb
Exec in host VM:            vctl execvm -c mydb /bin/ls

Untitled

vtcl run命令

PS C:\Users\admin> vctl run
Error: IMAGE must be provided
USAGE:
  vctl run [OPTIONS] IMAGE [COMMAND] [ARGUMENTS...]

OPTIONS:
  -c, --cpus int            Number of CPU cores (default 2)
  -d, --detach              Run the container in background
      --entrypoint string   Override the default entrypoint of the container image
  -e, --env strings         Environment variables to set in the container
  -h, --help                Help for run
      --hostname string     Host name of the container
  -i, --interactive         Keep STDIN open even if not attached
      --keepVM              [EXPERIMENTAL] Keep the host virtual machine running after container stops
  -l, --label strings       Set additional labels to the container (e.g. foo=bar)
  -m, --memory string       Limit on memory (MB/GB) available to the container (default "512m")
  -n, --name string         Assign a name to the container
  -r, --privileged          Run the container with extended privileges
  -p, --publish strings     Bind host network ports to container ports
      --rm                  Automatically remove the container when it exits
  -t, --tty                 Allocate a terminal for the container
  -v, --volume strings      Bind host folders to container folders
  -w, --workdir string      Working directory of the new process

EXAMPLES:
  # To run a new container using 'myImage' image.
  vctl run myImage

  # To set environment variables "FOO=BAR" when running a new container using 'myImage' image.
  vctl run --env="FOO=BAR" myImage

  # To set 4 CPU cores limit and 2GB memory limit for a new container using 'myImage' image. (In this case the virtual machine hosting the container will be configured with 4 CPU cores and 2560MB memory.)
  vctl run -c 4 -m 2g myImage

  # To run a new container in background. (detached from current terminal)
  vctl run --detach myImage

  # To assign name 'myContainer' to the new container to run.
  vctl run --name myContainer myImage

  # To keep the host virtual machine running after container stops for potential debug and troubleshooting needs.
  vctl run --keepVM myImage

  # To mount folder C:\toolchain on host to the new container using 'myImage' image.
  vctl run --volume C:\toolchain:/toolchain myImage

参考链接:https://docs.vmware.com/cn/VMware-Workstation-Pro/16.0/com.vmware.ws.using.doc/GUID-78E7339F-7294-4F3E-9AD0-1E14C201FA40.html

https://docs.vmware.com/cn/VMware-Fusion/12/com.vmware.fusion.using.doc/GUID-78E7339F-7294-4F3E-9AD0-1E14C201FA40.html

语法:https://docs.vmware.com/cn/VMware-Fusion/12/com.vmware.fusion.using.doc/GUID-9BFCCD98-96A2-4633-BF8F-52976CFE2877.html

示例:https://docs.vmware.com/cn/VMware-Fusion/12/com.vmware.fusion.using.doc/GUID-0A6DD1F8-97F5-480B-AEC7-13EC793C90C7.html

comments powered by Disqus