container

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

README

Container module

A Zbus service to start, stop and inspect containers. The service provides the interface defined here

Dependency

The module depends on the flister module to mount the container rootfs

Example usage

package main

import (
	"github.com/threefoldtech/zbus"
	"github.com/threefoldtech/zosbase/pkg"
	"github.com/threefoldtech/zosbase/pkg/stubs"
)

func main() {
	client, err := zbus.NewRedisClient("tcp://localhost:6379")
	if err != nil {
		panic(client)
	}

	containerd := stubs.NewContainerModuleStub(client)
	namespace := "example"

	// make sure u have a network namespace ready using ip
	// sudo ip netns add mynetns

	info := pkg.Container{
		Name: "test",
		FList: "https://hub.grid.tf/thabet/redis.flist",
		Env: []string{},
		Network: pkg.NetworkInfo{Namespace: "mynetns"},
		Mounts: nil,
		Entrypoint: "redis-server",
	}

	id, err := containerd.Run(namespace, info)

	if err != nil {
		panic(err)
	}

	// DO WORK WITH CONTAINER ...

	if err = containerd.Delete(namespace, id); err != nil {
		panic(err)
	}

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyRootFS is returned when RootFS field is empty when trying to create a container
	ErrEmptyRootFS = errors.New("RootFS of the container creation data cannot be empty")
)

Functions

func WithCPUCount

func WithCPUCount(cru uint) oci.SpecOpts

WithCPUCount configure the CPU cgroup to limit the amount of CPU used by the container

func WithMemoryLimit

func WithMemoryLimit(limit uint64) oci.SpecOpts

WithMemoryLimit sets the `Linux.LinuxResources.Memory.Limit` section to the `limit` specified if the `Linux` section is not `nil`. Additionally sets the `Windows.WindowsResources.Memory.Limit` section if the `Windows` section is not `nil`.

func WithRootfsPropagation

func WithRootfsPropagation(rootfsPropagation pkg.RootFSPropagation) oci.SpecOpts

WithRootfsPropagation makes the

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module implements pkg.Module interface

func New

func New(client zbus.Client, root string, containerd string) *Module

New return an new pkg.ContainerModule

func (*Module) Delete

func (c *Module) Delete(ns string, id pkg.ContainerID) error

Delete stops and remove a container

func (*Module) Exec

func (c *Module) Exec(ns string, containerID string, timeout time.Duration, args ...string) error

Exec executes a command inside the container

func (*Module) Inspect

func (c *Module) Inspect(ns string, id pkg.ContainerID) (result pkg.Container, err error)

Inspect returns the detail about a running container

func (*Module) List

func (c *Module) List(ns string) ([]pkg.ContainerID, error)

List all the existing container IDs from a certain namespace ns

func (*Module) ListNS

func (c *Module) ListNS() ([]string, error)

ListNS list the name of all the container namespaces

func (*Module) Logs

func (c *Module) Logs(ns string, containerID string) (logs string, err error)

Get logs of the container

func (*Module) Run

func (c *Module) Run(ns string, data pkg.Container) (id pkg.ContainerID, err error)

Run creates and starts a container

func (*Module) SignalDelete

func (c *Module) SignalDelete(ns string, id pkg.ContainerID) error

func (*Module) Watch

func (c *Module) Watch(ctx context.Context)

Watch start watching for events coming from containerd. Blocks forever. caller need to run this in a go routine

different events types are handled differently. Now, only TaskExit event is handled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL