github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/documentation/api/1.0/api.md (about) 1 # virtcontainers 1.0 API 2 3 The virtcontainers 1.0 API operates on two high level objects: 4 [Sandboxes](#sandbox-api) and [containers](#container-api): 5 6 * [Sandbox API](#sandbox-api) 7 * [Container API](#container-api) 8 * [Examples](#examples) 9 10 ## Sandbox API 11 12 The virtcontainers 1.0 sandbox API manages hardware virtualized 13 [sandbox lifecycles](#sandbox-functions). The virtcontainers sandbox 14 semantics strictly follow the 15 [Kubernetes](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/) ones. 16 17 The sandbox API allows callers to [create](#createsandbox), [delete](#deletesandbox), 18 [start](#startsandbox), [stop](#stopsandbox), [run](#runsandbox), [pause](#pausesandbox), 19 [resume](#resumesandbox) and [list](#listsandbox) VM (Virtual Machine) based sandboxes. 20 21 To initially create a sandbox, the API caller must prepare a 22 [`SandboxConfig`](#sandboxconfig) and pass it to either [`CreateSandbox`](#createsandbox) 23 or [`RunSandbox`](#runsandbox). Upon successful sandbox creation, the virtcontainers 24 API will return a [`VCSandbox`](#vcsandbox) interface back to the caller. 25 26 The `VCSandbox` interface is a sandbox abstraction hiding the internal and private 27 virtcontainers sandbox structure. It is a handle for API callers to manage the 28 sandbox lifecycle through the rest of the [sandbox API](#sandbox-functions). 29 30 * [Structures](#sandbox-structures) 31 * [Functions](#sandbox-functions) 32 33 ### Sandbox Structures 34 35 * [`SandboxConfig`](#sandboxconfig) 36 * [`Resources`](#resources) 37 * [`HypervisorType`](#hypervisortype) 38 * [`HypervisorConfig`](#hypervisorconfig) 39 * [`AgentType`](#agenttype) 40 * [`ProxyType`](#proxytype) 41 * [`ProxyConfig`](#proxyconfig) 42 * [`ShimType`](#shimtype) 43 * [`NetworkConfig`](#networkconfig) 44 * [`NetInterworkingModel`](#netinterworkingmodel) 45 * [`Volume`](#volume) 46 * [`Sandbox ContainerConfig`](#sandbox-containerconfig) 47 * [`Sandbox Cmd`](#sandbox-cmd) 48 * [`Sandbox Mount`](#sandbox-mount) 49 * [`Sandbox DeviceInfo`](#sandbox-deviceinfo) 50 * [`VCSandbox`](#vcsandbox) 51 52 #### `SandboxConfig` 53 ```Go 54 // SandboxConfig is a Sandbox configuration. 55 type SandboxConfig struct { 56 ID string 57 58 Hostname string 59 60 // Field specific to OCI specs, needed to setup all the hooks 61 Hooks Hooks 62 63 // VMConfig is the VM configuration to set for this sandbox. 64 VMConfig Resources 65 66 HypervisorType HypervisorType 67 HypervisorConfig HypervisorConfig 68 69 AgentType AgentType 70 AgentConfig interface{} 71 72 ProxyType ProxyType 73 ProxyConfig ProxyConfig 74 75 ShimType ShimType 76 ShimConfig interface{} 77 78 NetworkConfig NetworkConfig 79 80 // Volumes is a list of shared volumes between the host and the Sandbox. 81 Volumes []Volume 82 83 // Containers describe the list of containers within a Sandbox. 84 // This list can be empty and populated by adding containers 85 // to the Sandbox a posteriori. 86 Containers []ContainerConfig 87 88 // Annotations keys must be unique strings and must be name-spaced 89 // with e.g. reverse domain notation (org.clearlinux.key). 90 Annotations map[string]string 91 } 92 ``` 93 ##### `Resources` 94 ```Go 95 // Resources describes VM resources configuration. 96 type Resources struct { 97 // VCPUs is the number of available virtual CPUs. 98 VCPUs uint 99 100 // Memory is the amount of available memory in MiB. 101 Memory uint 102 } 103 ``` 104 105 ##### `HypervisorType` 106 ```Go 107 // HypervisorType describes an hypervisor type. 108 type HypervisorType string 109 110 const ( 111 // QemuHypervisor is the QEMU hypervisor. 112 QemuHypervisor HypervisorType = "qemu" 113 114 // MockHypervisor is a mock hypervisor for testing purposes 115 MockHypervisor HypervisorType = "mock" 116 ) 117 ``` 118 119 ##### `HypervisorConfig` 120 ```Go 121 // HypervisorConfig is the hypervisor configuration. 122 type HypervisorConfig struct { 123 // KernelPath is the guest kernel host path. 124 KernelPath string 125 126 // ImagePath is the guest image host path. 127 ImagePath string 128 129 // FirmwarePath is the bios host path 130 FirmwarePath string 131 132 // MachineAccelerators are machine specific accelerators 133 MachineAccelerators string 134 135 // CPUFeatures are cpu specific features 136 CPUFeatures string 137 138 // HypervisorPath is the hypervisor executable host path. 139 HypervisorPath string 140 141 // DisableBlockDeviceUse disallows a block device from being used. 142 DisableBlockDeviceUse bool 143 144 // Shared file system type: 145 // - virtio-9p (default) 146 // - virtio-fs 147 SharedFS string 148 149 // VirtioFSDaemon is the virtio-fs vhost-user daemon path 150 VirtioFSDaemon string 151 152 // VirtioFSCacheSize is the virtio-fs DAX cache size in MiB 153 VirtioFSCacheSize uint32 154 155 // VirtioFSCache cache mode for fs version cache or "none" 156 VirtioFSCache string 157 158 // KernelParams are additional guest kernel parameters. 159 KernelParams []Param 160 161 // HypervisorParams are additional hypervisor parameters. 162 HypervisorParams []Param 163 164 // HypervisorMachineType specifies the type of machine being 165 // emulated. 166 HypervisorMachineType string 167 168 // Debug changes the default hypervisor and kernel parameters to 169 // enable debug output where available. 170 Debug bool 171 172 // NumVCPUs specifies default number of vCPUs for the VM. 173 // Sandbox configuration VMConfig.VCPUs overwrites this. 174 NumVCPUs uint32 175 176 // DefaultMem specifies default memory size in MiB for the VM. 177 // Sandbox configuration VMConfig.Memory overwrites this. 178 MemorySize uint32 179 180 // DefaultBridges specifies default number of bridges for the VM. 181 // Bridges can be used to hot plug devices 182 DefaultBridges uint32 183 184 // MemPrealloc specifies if the memory should be pre-allocated 185 MemPrealloc bool 186 187 // HugePages specifies if the memory should be pre-allocated from huge pages 188 HugePages bool 189 190 // Realtime Used to enable/disable realtime 191 Realtime bool 192 193 // Mlock is used to control memory locking when Realtime is enabled 194 // Realtime=true and Mlock=false, allows for swapping out of VM memory 195 // enabling higher density 196 Mlock bool 197 198 // DisableNestingChecks is used to override customizations performed 199 // when running on top of another VMM. 200 DisableNestingChecks bool 201 } 202 ``` 203 204 ##### `AgentType` 205 ```Go 206 // AgentType describes the type of guest agent a Sandbox should run. 207 type AgentType string 208 209 const ( 210 // NoopAgentType is the No-Op agent. 211 NoopAgentType AgentType = "noop" 212 213 // KataContainersAgent is the Kata Containers agent. 214 KataContainersAgent AgentType = "kata" 215 216 // SocketTypeVSOCK is a VSOCK socket type for talking to an agent. 217 SocketTypeVSOCK = "vsock" 218 219 // SocketTypeUNIX is a UNIX socket type for talking to an agent. 220 // It typically means the agent is living behind a host proxy. 221 SocketTypeUNIX = "unix" 222 ) 223 ``` 224 225 ##### `ProxyType` 226 ```Go 227 // ProxyType describes a proxy type. 228 type ProxyType string 229 230 const ( 231 // NoopProxyType is the noopProxy. 232 NoopProxyType ProxyType = "noopProxy" 233 234 // NoProxyType is the noProxy. 235 NoProxyType ProxyType = "noProxy" 236 237 // KataProxyType is the kataProxy. 238 KataProxyType ProxyType = "kataProxy" 239 ) 240 ``` 241 242 ##### `ProxyConfig` 243 ```Go 244 // ProxyConfig is a structure storing information needed from any 245 // proxy in order to be properly initialized. 246 type ProxyConfig struct { 247 Path string 248 Debug bool 249 } 250 ``` 251 252 ##### `ShimType` 253 ```Go 254 // ShimType describes a shim type. 255 type ShimType string 256 257 const ( 258 // NoopShimType is the noopShim. 259 NoopShimType ShimType = "noopShim" 260 261 // KataShimType is the Kata Containers shim type. 262 KataShimType ShimType = "kataShim" 263 ) 264 ``` 265 266 ##### `NetworkConfig` 267 ```Go 268 // NetworkConfig is the network configuration related to a network. 269 type NetworkConfig struct { 270 NetNSPath string 271 InterworkingModel NetInterworkingModel 272 } 273 ``` 274 ###### `NetInterworkingModel` 275 ```Go 276 // NetInterworkingModel defines the network model connecting 277 // the network interface to the virtual machine. 278 type NetInterworkingModel int 279 280 const ( 281 // NetXConnectDefaultModel Ask to use DefaultNetInterworkingModel 282 NetXConnectDefaultModel NetInterworkingModel = iota 283 284 // NetXConnectMacVtapModel can be used when the Container network 285 // interface can be bridged using macvtap 286 NetXConnectMacVtapModel 287 288 // NetXConnectInvalidModel is the last item to check valid values by IsValid() 289 NetXConnectInvalidModel 290 ) 291 ``` 292 293 ##### `Volume` 294 ```Go 295 // Volume is a shared volume between the host and the VM, 296 // defined by its mount tag and its host path. 297 type Volume struct { 298 // MountTag is a label used as a hint to the guest. 299 MountTag string 300 301 // HostPath is the host filesystem path for this volume. 302 HostPath string 303 } 304 ``` 305 306 ##### Sandbox `ContainerConfig` 307 ```Go 308 // ContainerConfig describes one container runtime configuration. 309 type ContainerConfig struct { 310 ID string 311 312 // RootFs is the container workload image on the host. 313 RootFs string 314 315 // ReadOnlyRootfs indicates if the rootfs should be mounted readonly 316 ReadonlyRootfs bool 317 318 // Cmd specifies the command to run on a container 319 Cmd Cmd 320 321 // Annotations allow clients to store arbitrary values, 322 // for example to add additional status values required 323 // to support particular specifications. 324 Annotations map[string]string 325 326 Mounts []Mount 327 328 // Device configuration for devices that must be available within the container. 329 DeviceInfos []DeviceInfo 330 } 331 ``` 332 333 ###### Sandbox `Cmd` 334 ```Go 335 // Cmd represents a command to execute in a running container. 336 type Cmd struct { 337 Args []string 338 Envs []EnvVar 339 WorkDir string 340 341 // Note that these fields *MUST* remain as strings. 342 // 343 // The reason being that we want runtimes to be able to support CLI 344 // operations like "exec --user=". That option allows the 345 // specification of a user (either as a string username or a numeric 346 // UID), and may optionally also include a group (groupame or GID). 347 // 348 // Since this type is the interface to allow the runtime to specify 349 // the user and group the workload can run as, these user and group 350 // fields cannot be encoded as integer values since that would imply 351 // the runtime itself would need to perform a UID/GID lookup on the 352 // user-specified username/groupname. But that isn't practically 353 // possible given that to do so would require the runtime to access 354 // the image to allow it to interrogate the appropriate databases to 355 // convert the username/groupnames to UID/GID values. 356 // 357 // Note that this argument applies solely to the _runtime_ supporting 358 // a "--user=" option when running in a "standalone mode" - there is 359 // no issue when the runtime is called by a container manager since 360 // all the user and group mapping is handled by the container manager 361 // and specified to the runtime in terms of UID/GID's in the 362 // configuration file generated by the container manager. 363 User string 364 PrimaryGroup string 365 SupplementaryGroups []string 366 367 Interactive bool 368 Console string 369 Detach bool 370 NoNewPrivileges bool 371 Capabilities LinuxCapabilities 372 } 373 ``` 374 375 ###### Sandbox `Mount` 376 ```Go 377 // Mount describes a container mount. 378 type Mount struct { 379 Source string 380 Destination string 381 382 // Type specifies the type of filesystem to mount. 383 Type string 384 385 // Options list all the mount options of the filesystem. 386 Options []string 387 388 // HostPath used to store host side bind mount path 389 HostPath string 390 391 // ReadOnly specifies if the mount should be read only or not 392 ReadOnly bool 393 } 394 ``` 395 396 ###### Sandbox `DeviceInfo` 397 ```Go 398 // DeviceInfo is an embedded type that contains device data common to all types of devices. 399 type DeviceInfo struct { 400 // Device path on host 401 HostPath string 402 403 // Device path inside the container 404 ContainerPath string 405 406 // Type of device: c, b, u or p 407 // c , u - character(unbuffered) 408 // p - FIFO 409 // b - block(buffered) special file 410 // More info in mknod(1). 411 DevType string 412 413 // Major, minor numbers for device. 414 Major int64 415 Minor int64 416 417 // FileMode permission bits for the device. 418 FileMode os.FileMode 419 420 // id of the device owner. 421 UID uint32 422 423 // id of the device group. 424 GID uint32 425 426 // Hotplugged is used to store device state indicating if the 427 // device was hotplugged. 428 Hotplugged bool 429 430 // ID for the device that is passed to the hypervisor. 431 ID string 432 } 433 ``` 434 435 #### `VCSandbox` 436 ```Go 437 // VCSandbox is the Sandbox interface 438 // (required since virtcontainers.Sandbox only contains private fields) 439 type VCSandbox interface { 440 Annotations(key string) (string, error) 441 GetAllContainers() []VCContainer 442 GetAnnotations() map[string]string 443 GetContainer(containerID string) VCContainer 444 ID() string 445 SetAnnotations(annotations map[string]string) error 446 } 447 ``` 448 449 ### Sandbox Functions 450 451 * [`CreateSandbox`](#createsandbox) 452 * [`DeleteSandbox`](#deletesandbox) 453 * [`StartSandbox`](#startsandbox) 454 * [`StopSandbox`](#stopsandbox) 455 * [`RunSandbox`](#runsandbox) 456 * [`ListSandbox`](#listsandbox) 457 * [`StatusSandbox`](#statussandbox) 458 * [`PauseSandbox`](#pausesandbox) 459 * [`ResumeSandbox`](#resumesandbox) 460 461 #### `CreateSandbox` 462 ```Go 463 // CreateSandbox is the virtcontainers sandbox creation entry point. 464 // CreateSandbox creates a sandbox and its containers. It does not start them. 465 func CreateSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) 466 ``` 467 468 #### `DeleteSandbox` 469 ```Go 470 // DeleteSandbox is the virtcontainers sandbox deletion entry point. 471 // DeleteSandbox will stop an already running container and then delete it. 472 func DeleteSandbox(sandboxID string) (VCSandbox, error) 473 ``` 474 475 #### `StartSandbox` 476 ```Go 477 // StartSandbox is the virtcontainers sandbox starting entry point. 478 // StartSandbox will talk to the given hypervisor to start an existing 479 // sandbox and all its containers. 480 func StartSandbox(sandboxID string) (VCSandbox, error) 481 ``` 482 483 #### `StopSandbox` 484 ```Go 485 // StopSandbox is the virtcontainers sandbox stopping entry point. 486 // StopSandbox will talk to the given agent to stop an existing sandbox 487 // and destroy all containers within that sandbox. 488 func StopSandbox(sandboxID string) (VCSandbox, error) 489 ``` 490 491 #### `RunSandbox` 492 ```Go 493 // RunSandbox is the virtcontainers sandbox running entry point. 494 // RunSandbox creates a sandbox and its containers and then it starts them. 495 func RunSandbox(sandboxConfig SandboxConfig) (VCSandbox, error) 496 ``` 497 498 #### `ListSandbox` 499 ```Go 500 // ListSandbox is the virtcontainers sandbox listing entry point. 501 func ListSandbox() ([]SandboxStatus, error) 502 ``` 503 504 #### `StatusSandbox` 505 ```Go 506 // StatusSandbox is the virtcontainers sandbox status entry point. 507 func StatusSandbox(sandboxID string) (SandboxStatus, error) 508 ``` 509 510 #### `PauseSandbox` 511 ```Go 512 // PauseSandbox is the virtcontainers pausing entry point which pauses an 513 // already running sandbox. 514 func PauseSandbox(sandboxID string) (VCSandbox, error) 515 ``` 516 517 #### `ResumeSandbox` 518 ```Go 519 // ResumeSandbox is the virtcontainers resuming entry point which resumes 520 // (or unpauses) and already paused sandbox. 521 func ResumeSandbox(sandboxID string) (VCSandbox, error) 522 ``` 523 524 ## Container API 525 526 The virtcontainers 1.0 container API manages sandbox 527 [container lifecycles](#container-functions). 528 529 A virtcontainers container is process running inside a containerized 530 environment, as part of a hardware virtualized context. In other words, 531 a virtcontainers container is just a regular container running inside a 532 virtual machine's guest OS. 533 534 A virtcontainers container always belong to one and only one 535 virtcontainers sandbox, again following the 536 [Kubernetes](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview). 537 logic and semantics. 538 539 The container API allows callers to [create](#createcontainer), 540 [delete](#deletecontainer), [start](#startcontainer), [stop](#stopcontainer), 541 [kill](#killcontainer) and [observe](#statuscontainer) containers. It also 542 allows for running [additional processes](#entercontainer) inside a 543 specific container. 544 545 As a virtcontainers container is always linked to a sandbox, the entire container 546 API always takes a sandbox ID as its first argument. 547 548 To create a container, the API caller must prepare a 549 [`ContainerConfig`](#sandbox-containerconfig) and pass it to 550 [`CreateContainer`](#createcontainer) together with a sandbox ID. Upon successful 551 container creation, the virtcontainers API will return a 552 [`VCContainer`](#vccontainer) interface back to the caller. 553 554 The `VCContainer` interface is a container abstraction hiding the internal 555 and private virtcontainers container structure. It is a handle for API callers 556 to manage the container lifecycle through the rest of the 557 [container API](#container-functions). 558 559 * [Structures](#container-structures) 560 * [Functions](#container-functions) 561 562 ### Container Structures 563 564 * [Container `ContainerConfig`](#container-containerconfig) 565 * [Container `Cmd`](#container-cmd) 566 * [Container `Mount`](#container-mount) 567 * [Container `DeviceInfo`](#container-deviceinfo) 568 * [`Process`](#process) 569 * [`ContainerStatus`](#containerstatus) 570 * [`ProcessListOptions`](#processlistoptions) 571 * [`VCContainer`](#vccontainer) 572 573 574 #### Container `ContainerConfig` 575 ```Go 576 // ContainerConfig describes one container runtime configuration. 577 type ContainerConfig struct { 578 ID string 579 580 // RootFs is the container workload image on the host. 581 RootFs string 582 583 // ReadOnlyRootfs indicates if the rootfs should be mounted readonly 584 ReadonlyRootfs bool 585 586 // Cmd specifies the command to run on a container 587 Cmd Cmd 588 589 // Annotations allow clients to store arbitrary values, 590 // for example to add additional status values required 591 // to support particular specifications. 592 Annotations map[string]string 593 594 Mounts []Mount 595 596 // Device configuration for devices that must be available within the container. 597 DeviceInfos []DeviceInfo 598 } 599 ``` 600 601 ##### Container `Cmd` 602 ```Go 603 // Cmd represents a command to execute in a running container. 604 type Cmd struct { 605 Args []string 606 Envs []EnvVar 607 WorkDir string 608 609 // Note that these fields *MUST* remain as strings. 610 // 611 // The reason being that we want runtimes to be able to support CLI 612 // operations like "exec --user=". That option allows the 613 // specification of a user (either as a string username or a numeric 614 // UID), and may optionally also include a group (groupame or GID). 615 // 616 // Since this type is the interface to allow the runtime to specify 617 // the user and group the workload can run as, these user and group 618 // fields cannot be encoded as integer values since that would imply 619 // the runtime itself would need to perform a UID/GID lookup on the 620 // user-specified username/groupname. But that isn't practically 621 // possible given that to do so would require the runtime to access 622 // the image to allow it to interrogate the appropriate databases to 623 // convert the username/groupnames to UID/GID values. 624 // 625 // Note that this argument applies solely to the _runtime_ supporting 626 // a "--user=" option when running in a "standalone mode" - there is 627 // no issue when the runtime is called by a container manager since 628 // all the user and group mapping is handled by the container manager 629 // and specified to the runtime in terms of UID/GID's in the 630 // configuration file generated by the container manager. 631 User string 632 PrimaryGroup string 633 SupplementaryGroups []string 634 635 Interactive bool 636 Console string 637 Detach bool 638 NoNewPrivileges bool 639 Capabilities LinuxCapabilities 640 } 641 ``` 642 643 ##### Container `Mount` 644 ```Go 645 // Mount describes a container mount. 646 type Mount struct { 647 Source string 648 Destination string 649 650 // Type specifies the type of filesystem to mount. 651 Type string 652 653 // Options list all the mount options of the filesystem. 654 Options []string 655 656 // HostPath used to store host side bind mount path 657 HostPath string 658 659 // ReadOnly specifies if the mount should be read only or not 660 ReadOnly bool 661 } 662 ``` 663 664 ##### Container `DeviceInfo` 665 ```Go 666 // DeviceInfo is an embedded type that contains device data common to all types of devices. 667 type DeviceInfo struct { 668 // Device path on host 669 HostPath string 670 671 // Device path inside the container 672 ContainerPath string 673 674 // Type of device: c, b, u or p 675 // c , u - character(unbuffered) 676 // p - FIFO 677 // b - block(buffered) special file 678 // More info in mknod(1). 679 DevType string 680 681 // Major, minor numbers for device. 682 Major int64 683 Minor int64 684 685 // FileMode permission bits for the device. 686 FileMode os.FileMode 687 688 // id of the device owner. 689 UID uint32 690 691 // id of the device group. 692 GID uint32 693 694 // Hotplugged is used to store device state indicating if the 695 // device was hotplugged. 696 Hotplugged bool 697 698 // ID for the device that is passed to the hypervisor. 699 ID string 700 } 701 ``` 702 703 #### `Process` 704 ```Go 705 // Process gathers data related to a container process. 706 type Process struct { 707 // Token is the process execution context ID. It must be 708 // unique per sandbox. 709 // Token is used to manipulate processes for containers 710 // that have not started yet, and later identify them 711 // uniquely within a sandbox. 712 Token string 713 714 // Pid is the process ID as seen by the host software 715 // stack, e.g. CRI-O, containerd. This is typically the 716 // shim PID. 717 Pid int 718 719 StartTime time.Time 720 } 721 ``` 722 723 #### `ContainerStatus` 724 ```Go 725 // ContainerStatus describes a container status. 726 type ContainerStatus struct { 727 ID string 728 State State 729 PID int 730 StartTime time.Time 731 RootFs string 732 733 // Annotations allow clients to store arbitrary values, 734 // for example to add additional status values required 735 // to support particular specifications. 736 Annotations map[string]string 737 } 738 ``` 739 740 #### `ProcessListOptions` 741 ```Go 742 // ProcessListOptions contains the options used to list running 743 // processes inside the container 744 type ProcessListOptions struct { 745 // Format describes the output format to list the running processes. 746 // Formats are unrelated to ps(1) formats, only two formats can be specified: 747 // "json" and "table" 748 Format string 749 750 // Args contains the list of arguments to run ps(1) command. 751 // If Args is empty the agent will use "-ef" as options to ps(1). 752 Args []string 753 } 754 ``` 755 756 #### `VCContainer` 757 ```Go 758 // VCContainer is the Container interface 759 // (required since virtcontainers.Container only contains private fields) 760 type VCContainer interface { 761 GetAnnotations() map[string]string 762 GetPid() int 763 GetToken() string 764 ID() string 765 Sandbox() VCSandbox 766 Process() Process 767 } 768 ``` 769 770 ### Container Functions 771 772 * [`CreateContainer`](#createcontainer) 773 * [`DeleteContainer`](#deletecontainer) 774 * [`StartContainer`](#startcontainer) 775 * [`StopContainer`](#stopcontainer) 776 * [`EnterContainer`](#entercontainer) 777 * [`StatusContainer`](#statuscontainer) 778 * [`KillContainer`](#killcontainer) 779 * [`ProcessListContainer`](#processlistcontainer) 780 781 #### `CreateContainer` 782 ```Go 783 // CreateContainer is the virtcontainers container creation entry point. 784 // CreateContainer creates a container on a given sandbox. 785 func CreateContainer(sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) 786 ``` 787 788 #### `DeleteContainer` 789 ```Go 790 // DeleteContainer is the virtcontainers container deletion entry point. 791 // DeleteContainer deletes a Container from a Sandbox. If the container is running, 792 // it needs to be stopped first. 793 func DeleteContainer(sandboxID, containerID string) (VCContainer, error) 794 ``` 795 796 #### `StartContainer` 797 ```Go 798 // StartContainer is the virtcontainers container starting entry point. 799 // StartContainer starts an already created container. 800 func StartContainer(sandboxID, containerID string) (VCContainer, error) 801 ``` 802 803 #### `StopContainer` 804 ```Go 805 // StopContainer is the virtcontainers container stopping entry point. 806 // StopContainer stops an already running container. 807 func StopContainer(sandboxID, containerID string) (VCContainer, error) 808 ``` 809 810 #### `EnterContainer` 811 ```Go 812 // EnterContainer is the virtcontainers container command execution entry point. 813 // EnterContainer enters an already running container and runs a given command. 814 func EnterContainer(sandboxID, containerID string, cmd Cmd) (VCSandbox, VCContainer, *Process, error) 815 ``` 816 817 #### `StatusContainer` 818 ```Go 819 // StatusContainer is the virtcontainers container status entry point. 820 // StatusContainer returns a detailed container status. 821 func StatusContainer(sandboxID, containerID string) (ContainerStatus, error) 822 ``` 823 824 #### `KillContainer` 825 ```Go 826 // KillContainer is the virtcontainers entry point to send a signal 827 // to a container running inside a sandbox. If all is true, all processes in 828 // the container will be sent the signal. 829 func KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error 830 ``` 831 832 #### `ProcessListContainer` 833 ```Go 834 // ProcessListContainer is the virtcontainers entry point to list 835 // processes running inside a container 836 func ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) 837 ``` 838 839 ## Examples 840 841 ### Preparing and running a sandbox 842 843 ```Go 844 845 // This example creates and starts a single container sandbox, 846 // using qemu as the hypervisor and kata as the VM agent. 847 func Example_createAndStartSandbox() { 848 envs := []vc.EnvVar{ 849 { 850 Var: "PATH", 851 Value: "/bin:/usr/bin:/sbin:/usr/sbin", 852 }, 853 } 854 855 cmd := vc.Cmd{ 856 Args: strings.Split("/bin/sh", " "), 857 Envs: envs, 858 WorkDir: "/", 859 } 860 861 // Define the container command and bundle. 862 container := vc.ContainerConfig{ 863 ID: "1", 864 RootFs: containerRootfs, 865 Cmd: cmd, 866 } 867 868 // Sets the hypervisor configuration. 869 hypervisorConfig := vc.HypervisorConfig{ 870 KernelPath: "/usr/share/clear-containers/vmlinux.container", 871 ImagePath: "/usr/share/clear-containers/clear-containers.img", 872 HypervisorPath: "/usr/bin/qemu-system-x86_64", 873 } 874 875 // Use kata default values for the agent. 876 agConfig := vc.KataAgentConfig{} 877 878 // VM resources 879 vmConfig := vc.Resources{ 880 VCPUs: 4, 881 Memory: 1024, 882 } 883 884 // The sandbox configuration: 885 // - One container 886 // - Hypervisor is QEMU 887 // - Agent is kata 888 sandboxConfig := vc.SandboxConfig{ 889 VMConfig: vmConfig, 890 891 HypervisorType: vc.QemuHypervisor, 892 HypervisorConfig: hypervisorConfig, 893 894 AgentType: vc.KataContainersAgent 895 AgentConfig: agConfig, 896 897 Containers: []vc.ContainerConfig{container}, 898 } 899 900 _, err := vc.RunSandbox(sandboxConfig) 901 if err != nil { 902 fmt.Printf("Could not run sandbox: %s", err) 903 } 904 905 return 906 } 907 ```