### Install blackfriday-tool with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/russross/blackfriday/README.md Downloads and installs the blackfriday-tool command-line tool, which also installs blackfriday itself. The tool binary is installed in $GOPATH/bin and is statically linked. ```bash go get github.com/russross/blackfriday-tool ``` -------------------------------- ### Install Cobra with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/spf13/cobra/README.md Install the Cobra library and its generator executable using the go get command. ```bash go get -u github.com/spf13/cobra/cobra ``` -------------------------------- ### Example: start containers foo1 and foo2 Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_start.md Demonstrates starting two created containers (foo1 and foo2) with pouch start. The output shows the container names and the resulting status change from created to Up. ```bash $ pouch ps -a Name ID Status Created Image Runtime foo2 5a0ede created 1 second ago registry.hub.docker.com/library/busybox:latest runc foo1 e05637 created 6 seconds ago registry.hub.docker.com/library/busybox:latest runc $ pouch start foo1 foo2 foo1 foo2 $ pouch ps Name ID Status Created Image Runtime foo2 5a0ede Up 2 seconds 12 seconds ago registry.hub.docker.com/library/busybox:latest runc foo1 e05637 Up 3 seconds 17 seconds ago registry.hub.docker.com/library/busybox:latest runc ``` -------------------------------- ### Install Blackfriday v2 with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/russross/blackfriday/README.md Downloads, compiles, and installs the Blackfriday v2 package into your GOPATH. Requires Go and git installed. ```bash go get -u gopkg.in/russross/blackfriday.v2 ``` -------------------------------- ### Install gocheck with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/go-check/check/README.md Install the gocheck package using the go get command. This is the first step before importing the package. ```bash go get gopkg.in/check.v1 ``` -------------------------------- ### Install sockaddr CLI with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/hashicorp/go-sockaddr/README.md Install the sockaddr command-line utility using go get. This exposes nearly all functionality of the go-sockaddr library for administrative or testing purposes. ```text $ go get -u github.com/hashicorp/go-sockaddr/cmd/sockaddr ``` -------------------------------- ### Install gRPC-Go with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/google.golang.org/grpc/README.md Run this command to install the gRPC-Go library. Requires Go and a configured Go workspace. ```bash $ go get -u google.golang.org/grpc ``` -------------------------------- ### Install Bolt with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/boltdb/bolt/README.md Retrieves the Bolt library and installs the bolt command line utility into your $GOBIN path. ```sh $ go get github.com/boltdb/bolt/... ``` -------------------------------- ### Install gorilla/mux with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/gorilla/mux/README.md Install the gorilla/mux package using the Go toolchain. Requires a correctly configured Go environment. ```sh go get -u github.com/gorilla/mux ``` -------------------------------- ### Install bbolt with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/go.etcd.io/bbolt/README.md Retrieves the bbolt library and installs the 'bolt' command line utility into your $GOBIN path. Requires Go to be installed first. ```sh $ go get go.etcd.io/bbolt/... ``` -------------------------------- ### Install dumb-init Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_rich_container.md Downloads and installs dumb-init version 1.2.1 to /usr/bin/dumb-init and makes it executable. ```shell # wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 # chmod +x /usr/bin/dumb-init ``` -------------------------------- ### Build and run SCTP example server and client Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/ishidawataru/sctp/README.md Commands to build and run the example SCTP server and client from the example directory. The server binds to the specified IP addresses and port, and the client connects to them. ```bash $ cd example $ go build $ # run example SCTP server $ ./example -server -port 1000 -ip 10.10.0.1,10.20.0.1 $ # run example SCTP client $ ./example -port 1000 -ip 10.10.0.1,10.20.0.1 ``` -------------------------------- ### Install etcd/client with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/coreos/etcd/client/README.md Install the etcd/client Go library using the go get command. ```bash go get github.com/coreos/etcd/client ``` -------------------------------- ### Install and run h2i Source: https://github.com/alibaba/pouch/blob/master/vendor/golang.org/x/net/http2/h2i/README.md Install the h2i tool with go get and start an interactive session against a host. The host is required as a command-line argument. ```bash $ go get golang.org/x/net/http2/h2i $ h2i ``` -------------------------------- ### Install otgrpc package Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc/README.md Install the otgrpc package using go get. ```bash go get github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc ``` -------------------------------- ### Basic etcd/client usage: set and get keys Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/coreos/etcd/client/README.md Shows how to create a client, set a key, and get its value. Requires an etcd server running at the specified endpoint. The example sets a per-request timeout to fail fast when the endpoint is unavailable. ```go package main import ( "log" "time" "context" "github.com/coreos/etcd/client" ) func main() { cfg := client.Config{ Endpoints: []string{"http://127.0.0.1:2379"}, Transport: client.DefaultTransport, // set timeout per request to fail fast when the target endpoint is unavailable HeaderTimeoutPerRequest: time.Second, } c, err := client.New(cfg) if err != nil { log.Fatal(err) } kapi := client.NewKeysAPI(c) // set "/foo" key with "bar" value log.Print("Setting '/foo' key with 'bar' value") resp, err := kapi.Set(context.Background(), "/foo", "bar", nil) if err != nil { log.Fatal(err) } else { // print common key info log.Printf("Set is done. Metadata is %q\n", resp) } // get "/foo" key's value log.Print("Getting '/foo' key value") resp, err = kapi.Get(context.Background(), "/foo", nil) if err != nil { log.Fatal(err) } else { // print common key info log.Printf("Get is done. Metadata is %q\n", resp) // print value log.Printf("%q key has %q value\n", resp.Node.Key, resp.Node.Value) } } ``` -------------------------------- ### Quick and dirty runc installation with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/BUILDING.md Downloads runc binary without version information; not recommended for production. ```sh go get github.com/opencontainers/runc ``` -------------------------------- ### Start pouchd daemon Source: https://github.com/alibaba/pouch/blob/master/INSTALLATION.md Run the pouchd daemon with all needed binaries installed. The output shows containerd startup logs, including a warning that the btrfs snapshotter cannot be used because the path is not a btrfs filesystem. ```shell $ pouchd INFO[0000] starting containerd module=containerd revision=773c489c9c1b21a6d78b5c538cd395416ec50f88 version=v1.0.3 INFO[0000] setting subreaper... module=containerd INFO[0000] loading plugin "io.containerd.content.v1.content"... module=containerd type=io.containerd.content.v1 INFO[0000] loading plugin "io.containerd.snapshotter.v1.btrfs"... module=containerd type=io.containerd.snapshotter.v1 WARN[0000] failed to load plugin io.containerd.snapshotter.v1.btrfs error="path /var/lib/containerd/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter" module=containerd INFO[0000] loading plugin "io.containerd.snapshotter.v1.overlayfs"... module=containerd type=io.containerd.snapshotter.v1 INFO[0000] loading plugin "io.containerd.metadata.v1.bolt"... module=containerd type=io.containerd.metadata.v1 WARN[0000] could not use snapshotter btrfs in metadata plugin error="path /var/lib/containerd/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter" module="containerd/io.containerd.metadata.v1.bolt" INFO[0000] loading plugin "io.containerd.differ.v1.walking"... module=containerd type=io.containerd.differ.v1 INFO[0000] loading plugin "io.containerd.grpc.v1.containers"... module=containerd type=io.containerd.grpc.v1 ``` -------------------------------- ### Install Kubernetes components on Ubuntu 16.04+ Source: https://github.com/alibaba/pouch/blob/master/docs/kubernetes/pouch_with_kubernetes_deploying_aliyun.md Installs kubelet, kubeadm, and kubectl version 1.9.4-00 via apt. ```sh RELEASE="v1.9.4-00" apt-get update apt-get -y install kubelet=$RELEASE kubeadm=$RELEASE kubectl=$RELEASE ``` -------------------------------- ### Complete runnable mux server example Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/gorilla/mux/README.md A full, runnable mux-based HTTP server that binds to port 8000 and serves a single route. The YourHandler function writes "Gorilla!\n" to the response. Uses log.Fatal to start the server. ```go package main import ( "net/http" "log" "github.com/gorilla/mux" ) func YourHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Gorilla!\n")) } func main() { r := mux.NewRouter() // Routes consist of a path and a handler function. r.HandleFunc("/", YourHandler) // Bind to a port and pass our router in log.Fatal(http.ListenAndServe(":8000", r)) } ``` -------------------------------- ### Build runv from source Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_runV.md Build and install runv from source code after installing required build tools. ```bash sudo apt-get install autotools-dev sudo apt-get install automake cd runv ./autogen.sh ./configure make sudo make install ``` -------------------------------- ### Install pflag with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/spf13/pflag/README.md Install the pflag package using the standard Go command. ```bash go get github.com/spf13/pflag ``` -------------------------------- ### Start PouchContainer on Alibaba Cloud Linux 2 Source: https://github.com/alibaba/pouch/blob/master/INSTALLATION.md Starts the PouchContainer service using systemctl. After starting, you can pull images and run containers. ```bash sudo systemctl start pouch ``` -------------------------------- ### pouch start options Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_start.md Lists the options available for the pouch start command, including attach, checkpoint, detach-keys, help, and interactive. ```bash -a, --attach Attach container's STDOUT and STDERR --checkpoint string Restore container state from the checkpoint --checkpoint-dir string Directory to store checkpoints images --detach-keys string Override the key sequence for detaching a container -h, --help help for start -i, --interactive Attach container's STDIN ``` -------------------------------- ### Install QEMU on Ubuntu Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_kata.md Install QEMU and KVM on Ubuntu physical machines to run VMs for Kata Containers. ```bash sudo apt-get install -y qemu qemu-kvm ``` -------------------------------- ### Install Codec with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/hashicorp/go-msgpack/codec/README.md Install the codec library using the standard Go tool. This command fetches the package from GitHub. ```bash go get github.com/ugorji/go/codec ``` -------------------------------- ### pouch start command synopsis Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_start.md Shows the usage syntax for the pouch start command, which starts one or more created or stopped containers. ```bash pouch start [OPTIONS] CONTAINER [CONTAINER...] ``` -------------------------------- ### Typical usage model for codec encoder/decoder and RPC Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/hashicorp/go-msgpack/codec/README.md Shows the standard setup for creating a codec handle, configuring extensions, using encoder/decoder, and setting up RPC server and client. The example uses BincHandle by default but can switch to MsgpackHandle by changing the handle variable. ```go // create and configure Handle var ( bh codec.BincHandle mh codec.MsgpackHandle ) mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) // configure extensions // e.g. for msgpack, define functions and enable Time support for tag 1 // mh.AddExt(reflect.TypeOf(time.Time{}), 1, myMsgpackTimeEncodeExtFn, myMsgpackTimeDecodeExtFn) // create and use decoder/encoder var ( r io.Reader w io.Writer b []byte h = &bh // or mh to use msgpack ) dec = codec.NewDecoder(r, h) dec = codec.NewDecoderBytes(b, h) err = dec.Decode(&v) enc = codec.NewEncoder(w, h) enc = codec.NewEncoderBytes(&b, h) err = enc.Encode(v) //RPC Server go func() { for { conn, err := listener.Accept() rpcCodec := codec.GoRpc.ServerCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) rpc.ServeCodec(rpcCodec) } }() //RPC Communication (client side) conn, err = net.Dial("tcp", "localhost:5555") rpcCodec := codec.GoRpc.ClientCodec(conn, h) //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) client := rpc.NewClientWithCodec(rpcCodec) ``` -------------------------------- ### Install containerd binaries to /usr/local/bin Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/BUILDING.md Installs the built binaries into /usr/local/bin. ```sudo sudo make install ``` -------------------------------- ### Build and install PouchContainer binaries Source: https://github.com/alibaba/pouch/blob/master/INSTALLATION.md Compile pouch and pouchd binaries into the current bin directory and install them to /usr/local/bin by default. ```shell make build && make install ``` -------------------------------- ### Install apt HTTPS prerequisites on Ubuntu Source: https://github.com/alibaba/pouch/blob/master/INSTALLATION.md Installs packages to allow apt to use a repository over HTTPS. ```bash sudo apt-get install curl apt-transport-https ca-certificates software-properties-common ``` -------------------------------- ### Install CNI on Ubuntu 16.04+ Source: https://github.com/alibaba/pouch/blob/master/docs/kubernetes/pouch_with_kubernetes_deploying_aliyun.md Installs the kubernetes-cni package via apt. ```shell apt-get -y install kubernetes-cni ``` -------------------------------- ### Start PouchContainer on Ubuntu Source: https://github.com/alibaba/pouch/blob/master/INSTALLATION.md Starts the PouchContainer service using the service command. After starting, you can pull images and run containers. ```bash sudo service pouch start ``` -------------------------------- ### Install and build with go tool Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/miekg/dns/README.md Use the go tool to fetch and build the package after setting up GOPATH. ```shell go get github.com/miekg/dns ``` ```shell go build github.com/miekg/dns ``` -------------------------------- ### Build hyperstart Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_runV.md Build guest kernel and initrd.img from hyperstart source code. ```bash cd hyperstart ./autogen.sh ./configure sudo make ``` -------------------------------- ### Start containerd daemon Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/BUILDING.md Starts the containerd daemon with a config file. ```sh containerd --config config.toml ``` -------------------------------- ### Install and create feature branch Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md Commands to install fsnotify via go get and create a feature branch for development. ```bash go get -u github.com/fsnotify/fsnotify ``` ```bash git checkout -b my-new-feature ``` -------------------------------- ### Setup Kubernetes apt repository on Ubuntu 16.04+ Source: https://github.com/alibaba/pouch/blob/master/docs/kubernetes/pouch_with_kubernetes_deploying_aliyun.md Adds the Aliyun Kubernetes apt repository and GPG key. ```sh curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - cat < /etc/apt/sources.list.d/kubernetes.list deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main EOF ``` -------------------------------- ### Build and install runc from source Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/BUILDING.md Builds and installs runc from the source directory, recommended for proper versioning. ```sh cd $GOPATH/src/github.com/opencontainers/runc make make install ``` -------------------------------- ### Set up build path for tests Source: https://github.com/alibaba/pouch/blob/master/docs/test/test.md Create a build folder and add it to GOPATH. Note that files in /tmp may be deleted after reboot. ```bash BUILDPATH=/tmp/pouchbuild export GOPATH=$GOPATH:$BUILDPATH ``` -------------------------------- ### Install govalidator with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/asaskevich/govalidator/README.md Install the govalidator package using the standard go get command. ```bash go get github.com/asaskevich/govalidator ``` -------------------------------- ### Example: pouch events with since filter Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_events.md Displays real-time events from the daemon starting from a specified timestamp. The output shows volume and container events with details. ```bash $ pouch events -s "2018-08-10T10:52:05" 2018-08-10T10:53:15.071664386-04:00 volume create 9fff54f207615ccc5a29477f5ae2234c6b804ed8aad2f0dfc0dccb0cc69d4d12 (driver=local) 2018-08-10T10:53:15.091131306-04:00 container create f2b58eb6bc616d7a22bdb89de50b3f04e2c23134accdec1a9b9a7490d609d34c (image=registry.hub.docker.com/library/centos:latest, name=test) 2018-08-10T10:53:15.537704818-04:00 container start f2b58eb6bc616d7a22bdb89de50b3f04e2c23134accdec1a9b9a7490d609d34c (image=registry.hub.docker.com/library/centos:latest, name=test) ``` -------------------------------- ### Install mapstructure with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/mitchellh/mapstructure/README.md Standard installation command for the mapstructure Go library using go get. ```bash $ go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Initialize flags and config in init() Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/spf13/cobra/README.md Example init() function that sets up persistent flags and Viper configuration for the root command. ```go import ( "fmt" "os" homedir "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" ) func init() { cobra.OnInitialize(initConfig) rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") rootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "", "base project directory eg. github.com/spf13/") rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "Author name for copyright attribution") rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "Name of license for the project (can provide `licensetext` in config)") rootCmd.PersistentFlags().Bool("viper", true, "Use Viper for configuration") viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author")) viper.BindPFlag("projectbase", rootCmd.PersistentFlags().Lookup("projectbase")) viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper")) viper.SetDefault("author", "NAME HERE ") viper.SetDefault("license", "apache") } func initConfig() { // Don't forget to read config either from cfgFile or from home directory! if cfgFile != "" { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { // Find home directory. home, err := homedir.Dir() if err != nil { fmt.Println(err) os.Exit(1) } // Search config in home directory with name ".cobra" (without extension). viper.AddConfigPath(home) viper.SetConfigName(".cobra") } if err := viper.ReadInConfig(); err != nil { fmt.Println("Can't read config:", err) os.Exit(1) } } ``` -------------------------------- ### Install crictl via go get Source: https://github.com/alibaba/pouch/blob/master/docs/kubernetes/pouch_with_cri_verification.md Installs the CRI CLI tool crictl using the go get command. Requires Go installed and GOPATH set before running. ```bash go get github.com/kubernetes-incubator/cri-tools/cmd/crictl ``` -------------------------------- ### Install flock with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/gofrs/flock/README.md Install the flock package using the go get command. Requires Go 1.7 or later. ```bash go get -u github.com/gofrs/flock ``` -------------------------------- ### Basic executor usage with exec.Command Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/contiv/executor/README.md Shows how to create an executor, start it, get the PID, print a string representation, and wait for termination. The Wait call returns an ExecResult with an ExitStatus field, which is 0 for the example command. ```go e := executor.New(exec.Command("/bin/sh", "echo hello")) e.Start() // start fmt.Println(e.PID()) // get the pid fmt.Printf("%v\n", e) // pretty string output er, err := e.Wait(context.Background()) // wait for termination fmt.Println(er.ExitStatus) // => 0 ``` -------------------------------- ### Prometheus metrics output from pouchd Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_prometheus.md Example output from GET http://127.0.0.1:4243/metrics after starting pouchd with `pouchd -l tcp://0.0.0.0:4243`. Shows prometheus-formatted metrics including Go runtime, HTTP request/response sizes, and pouch image pull latency. ```text # HELP go_gc_duration_seconds A summary of the GC invocation durations. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 0.000111176 go_gc_duration_seconds{quantile="0.25"} 0.000198062 go_gc_duration_seconds{quantile="0.5"} 0.000269599 go_gc_duration_seconds{quantile="0.75"} 0.000474291 go_gc_duration_seconds{quantile="1"} 0.002013351 go_gc_duration_seconds_sum 0.021835193 go_gc_duration_seconds_count 52 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge go_goroutines 22 # HELP go_info Information about the Go environment. # TYPE go_info gauge go_info{version="go1.9"} 1 ... # HELP http_request_size_bytes The HTTP request sizes in bytes. # TYPE http_request_size_bytes summary http_request_size_bytes{handler="prometheus",quantile="0.5"} NaN http_request_size_bytes{handler="prometheus",quantile="0.9"} NaN http_request_size_bytes{handler="prometheus",quantile="0.99"} NaN http_request_size_bytes_sum{handler="prometheus"} 0 http_request_size_bytes_count{handler="prometheus"} 0 # HELP http_response_size_bytes The HTTP response sizes in bytes. # TYPE http_response_size_bytes summary http_response_size_bytes{handler="prometheus",quantile="0.5"} NaN http_response_size_bytes{handler="prometheus",quantile="0.9"} NaN http_response_size_bytes{handler="prometheus",quantile="0.99"} NaN http_response_size_bytes_sum{handler="prometheus"} 0 http_response_size_bytes_count{handler="prometheus"} 0 # HELP pouch_image_pull_latency_microseconds Latency in microseconds to pull a image. # TYPE pouch_image_pull_latency_microseconds summary pouch_image_pull_latency_microseconds{image="docker.io/library/ubuntu:latest",quantile="0.5"} 3.7803132e+07 pouch_image_pull_latency_microseconds{image="docker.io/library/ubuntu:latest",quantile="0.9"} 3.7803132e+07 pouch_image_pull_latency_microseconds{image="docker.io/library/ubuntu:latest",quantile="0.99"} 3.7803132e+07 pouch_image_pull_latency_microseconds_sum{image="docker.io/library/ubuntu:latest"} 3.7803132e+07 pouch_image_pull_latency_microseconds_count{image="docker.io/library/ubuntu:latest"} 1 # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # TYPE process_cpu_seconds_total counter process_cpu_seconds_total 4.78 # HELP process_max_fds Maximum number of open file descriptors. # TYPE process_max_fds gauge process_max_fds 1024 # HELP process_open_fds Number of open file descriptors. # TYPE process_open_fds gauge process_open_fds 9 # HELP process_resident_memory_bytes Resident memory size in bytes. # TYPE process_resident_memory_bytes gauge process_resident_memory_bytes 3.4521088e+07 # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # TYPE process_start_time_seconds gauge process_start_time_seconds 1.51064406778e+09 # HELP process_virtual_memory_bytes Virtual memory size in bytes. # TYPE process_virtual_memory_bytes gauge process_virtual_memory_bytes 4.91610112e+08 ``` -------------------------------- ### Example: run and upgrade a container Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_upgrade.md Demonstrates running a container and then upgrading it with a new image. The output shows the container ID and the container name. ```bash $ pouch run -d -m 20m --name test registry.hub.docker.com/library/busybox:latest 4c58d27f58d38776dda31c01c897bbf554c802a9b80ae4dc20be1337f8a969f2 $ pouch upgrade --image registry.hub.docker.com/library/hello-world:latest test test ``` -------------------------------- ### Use snapshot filesystems Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/README.md Pulls an image and unpacks it, then creates containers with RW or readonly snapshots. ```go // pull an image and unpack it into the configured snapshotter image, err := client.Pull(context, "docker.io/library/redis:latest", containerd.WithPullUnpack) // allocate a new RW root filesystem for a container based on the image redis, err := client.NewContainer(context, "redis-master", containerd.WithNewSnapshot("redis-rootfs", image), containerd.WithNewSpec(oci.WithImageConfig(image)), ) // use a readonly filesystem with multiple containers for i := 0; i < 10; i++ { id := fmt.Sprintf("id-%s", i) container, err := client.NewContainer(ctx, id, containerd.WithNewSnapshotView(id, image), containerd.WithNewSpec(oci.WithImageConfig(image)), ) } ``` -------------------------------- ### Install structs package Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/fatih/structs/README.md Install the structs package using go get. ```bash go get github.com/fatih/structs ``` -------------------------------- ### Install the TOML package with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/BurntSushi/toml/README.md Installation command for the BurntSushi/toml package. ```bash go get github.com/BurntSushi/toml ``` -------------------------------- ### Download and install protoc 3.5.0 for 64-bit Linux Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/BUILDING.md Downloads and installs the protoc 3.5.0 release into /usr/local on a 64-bit Linux host. ```sh $ wget -c https://github.com/google/protobuf/releases/download/v3.5.0/protoc-3.5.0-linux-x86_64.zip $ sudo unzip protoc-3.5.0-linux-x86_64.zip -d /usr/local ``` -------------------------------- ### Install yaml package with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/gopkg.in/yaml.v2/README.md Run this command to install the yaml package from gopkg.in/yaml.v2. ```bash go get gopkg.in/yaml.v2 ``` -------------------------------- ### Install hashstructure with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/mitchellh/hashstructure/README.md Standard installation command for the hashstructure library using Go's package manager. ```bash $ go get github.com/mitchellh/hashstructure ``` -------------------------------- ### Install govendor Source: https://github.com/alibaba/pouch/blob/master/vendor/README.md Install the govendor tool using the standard Go get command. PouchContainer uses govendor version v1.0.8. ```bash go get -u github.com/kardianos/govendor ``` -------------------------------- ### Example containerd plugin configuration Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/PLUGINS.md Shows the `[plugins]` configuration section for containerd, with per-plugin sections like `[plugins.cgroups]` and `[plugins.cri]`. Includes settings for CRI, CNI, and registry mirrors. ```toml [plugins] [plugins.cgroups] no_prometheus = false [plugins.cri] stream_server_address = "" stream_server_port = "10010" enable_selinux = false sandbox_image = "k8s.gcr.io/pause:3.1" stats_collect_period = 10 systemd_cgroup = false [plugins.cri.containerd] snapshotter = "overlayfs" [plugins.cri.containerd.default_runtime] runtime_type = "io.containerd.runtime.v1.linux" runtime_engine = "" runtime_root = "" [plugins.cri.containerd.untrusted_workload_runtime] runtime_type = "" runtime_engine = "" runtime_root = "" [plugins.cri.cni] bin_dir = "/opt/cni/bin" conf_dir = "/etc/cni/net.d" [plugins.cri.registry] [plugins.cri.registry.mirrors] [plugins.cri.registry.mirrors."docker.io"] endpoint = ["https://registry-1.docker.io"] ``` -------------------------------- ### Install netns package with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/vishvananda/netns/README.md Use go get to fetch the netns package. Requires elevated privileges for namespace operations. ```bash go get github.com/vishvananda/netns ``` -------------------------------- ### Copy hyperstart artifacts Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_runV.md Copy the built guest kernel and initrd.img to the default directory runv expects. ```bash mkdir /var/lib/hyper/ cp build/{kernel,hyper-initrd.img} /var/lib/hyper/ ``` -------------------------------- ### Install dbus package with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/godbus/dbus/README.markdown Install the dbus library using Go's package manager. Requires Go 1.1 and a configured GOPATH. ```bash go get github.com/godbus/dbus ``` -------------------------------- ### Install aec with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/morikuni/aec/README.md Install the aec package using the standard Go command. Requires a Go environment with network access. ```bash go get github.com/morikuni/aec ``` -------------------------------- ### Build URL with host and query variables Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/gorilla/mux/README.md Defines a route with host, path, and query variables, then builds the full URL. The result is 'http://news.domain.com/articles/technology/42?filter=gorilla'. ```go r := mux.NewRouter() r.Host("{subdomain}.domain.com"). Path("/articles/{category}/{id:[0-9]+}"). Queries("filter", "{filter}"). HandlerFunc(ArticleHandler). Name("article") // url.String() will be "http://news.domain.com/articles/technology/42?filter=gorilla" url, err := r.Get("article").URL("subdomain", "news", "category", "technology", "id", "42", "filter", "gorilla") ``` -------------------------------- ### Start Dragonfly proxy with df-daemon Source: https://github.com/alibaba/pouch/blob/master/docs/features/pouch_with_dragonfly.md Start the Dragonfly proxy using the df-daemon command. Add the --verbose flag to get debug logs. Logs are stored in ~/.small-dragonfly/logs. ```bash /usr/local/bin/df-client/df-daemon --registry https://reg.docker.alibaba-inc.com ``` -------------------------------- ### pouch run examples with output Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_run.md Demonstrates running a container with a command, detaching, and using a device. Includes the resulting container status and output. ```bash $ pouch run --name test registry.hub.docker.com/library/busybox:latest echo "hi" hi $ pouch ps -a Name ID Status Image Runtime Created test 23f852 stopped registry.hub.docker.com/library/busybox:latest runc 4 seconds ago $ pouch run -d --name test registry.hub.docker.com/library/busybox:latest 90719b5f9a455b3314a49e72e3ecb9962f215e0f90153aa8911882acf2ba2c84 $ pouch ps -a Name ID Status Image Runtime Created test 90719b stopped registry.hub.docker.com/library/busybox:latest runc 5 seconds ago $ pouch run --device /dev/zero:/dev/testDev:rwm --name test registry.hub.docker.com/library/busybox:latest ls -l /dev/testDev crw-rw-rw- 1 root root 1, 3 Jan 8 09:40 /dev/testnull ``` -------------------------------- ### Install Cobra generator with go get Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/spf13/cobra/cobra/README.md Compiles the cobra command and places the executable in $GOPATH/bin. ```bash go get github.com/spf13/cobra/cobra ``` -------------------------------- ### Implement snapshot proxy plugin in Go Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/PLUGINS.md Creates a snapshot plugin binary that listens on a Unix socket and serves the gRPC Snapshots API. Requires a snapshotter implementation (here native) and a root directory. Run with ' ' arguments. ```go package main import ( "fmt" "net" "os" "google.golang.org/grpc" snapshotsapi "github.com/containerd/containerd/api/services/snapshots/v1" "github.com/containerd/containerd/contrib/snapshotservice" "github.com/containerd/containerd/snapshots/native" ) func main() { // Provide a unix address to listen to, this will be the `address` // in the `proxy_plugin` configuration. // The root will be used to store the snapshots. if len(os.Args) < 3 { fmt.Printf("invalid args: usage: %s \n", os.Args[0]) os.Exit(1) } // Create a gRPC server rpc := grpc.NewServer() // Configure your custom snapshotter, this example uses the native // snapshotter and a root directory. Your custom snapshotter will be // much more useful than using a snapshotter which is already included. // https://godoc.org/github.com/containerd/containerd/snapshots#Snapshotter sn, err := native.NewSnapshotter(os.Args[2]) if err != nil { fmt.Printf("error: %v\n", err) os.Exit(1) } // Convert the snapshotter to a gRPC service, // example in github.com/containerd/containerd/contrib/snapshotservice service := snapshotservice.FromSnapshotter(sn) // Register the service with the gRPC server snapshotsapi.RegisterSnapshotsServer(rpc, service) // Listen and serve l, err := net.Listen("unix", os.Args[1]) if err != nil { fmt.Printf("error: %v\n", err) os.Exit(1) } if err := rpc.Serve(l); err != nil { fmt.Printf("error: %v\n", err) os.Exit(1) } } ``` -------------------------------- ### Create and manage a task Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/containerd/containerd/README.md Creates a task from a container, starts it, and waits for it to exit. ```go // create a new task task, err := redis.NewTask(context, cio.Stdio) defer task.Delete(context) // the task is now running and has a pid that can be use to setup networking // or other runtime settings outside of containerd pid := task.Pid() // start the redis-server process inside the container err := task.Start(context) // wait for the task to exit and get the exit status status, err := task.Wait(context) ``` -------------------------------- ### Retrieve route variables with mux.Vars() Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/gorilla/mux/README.md Use mux.Vars(r) to get a map of route variables. The example writes the category variable to the response. ```go func ArticlesCategoryHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Category: %v\n", vars["category"]) } ``` -------------------------------- ### Example command with argument: git clone URL --bare Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/spf13/cobra/README.md Shows a command 'clone' with an argument 'URL' and a flag '--bare'. ```bash git clone URL --bare ``` -------------------------------- ### Fenced code block with language Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/russross/blackfriday/README.md Demonstrates how to mark a fenced code block with a language for syntax highlighting. Use 3 or more backticks to start and end the block. ```go ``` go func getTrue() bool { return true } ``` ``` -------------------------------- ### Example: pouch inspect 08e Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_inspect.md Displays detailed information about the container with ID prefix '08e'. The output is a JSON object containing container metadata such as ID, state, image, and configuration. ```bash $ pouch inspect 08e [ { "Id": "08ee444faa3c6634ecdecea26de46e8a6a16efefd9afb72eb3457320b333fc60", "Created": "2017-12-04 14:48:59", "Path": "", "Args": null, "State": { "StartedAt": "0001-01-01T00:00:00Z", "Status": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Pid": 25006, "ExitCode": 0, "Error": "" }, "Image": "registry.docker-cn.com/library/centos:latest", "ResolvConfPath": "", "HostnamePath": "", "HostsPath": "", "LogPath": "", "Name": "08ee44", "RestartCount": 0, "Driver": "", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": null, "HostRootPath": "" } ] ``` -------------------------------- ### Client example (connecting to mirroring server without auth) Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/docker/spdystream/README.md Connects to a TCP server on localhost:8080, creates a spdy connection, and sends a message. Requires a running server that mirrors data back. The stream is read after writing, and the response is printed. ```go package main import ( "fmt" "github.com/docker/spdystream" "net" "net/http" ) func main() { conn, err := net.Dial("tcp", "localhost:8080") if err != nil { panic(err) } spdyConn, err := spdystream.NewConnection(conn, false) if err != nil { panic(err) } go spdyConn.Serve(spdystream.NoOpStreamHandler) stream, err := spdyConn.CreateStream(http.Header{}, nil, false) if err != nil { panic(err) } stream.Wait() fmt.Fprint(stream, "Writing to stream") buf := make([]byte, 25) stream.Read(buf) fmt.Println(string(buf)) stream.Close() } ``` -------------------------------- ### Define ValidArgs for subcommand Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/spf13/cobra/bash_completions.md Shows how to set ValidArgs on a subcommand to provide completions for nouns. In this example, 'get' subcommand has valid args 'pod', 'node', 'service', 'replicationcontroller'. This allows tab completion to show these nouns. ```go validArgs []string = { "pod", "node", "service", "replicationcontroller" } cmd := &cobra.Command{ Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)", Short: "Display one or many resources", Long: get_long, Example: get_example, Run: func(cmd *cobra.Command, args []string) { err := RunGet(f, out, cmd, args) util.CheckErr(err) }, ValidArgs: validArgs, } ``` -------------------------------- ### Basic usage of iradix.Tree Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/hashicorp/go-immutable-radix/README.md Creates an immutable radix tree, inserts key-value pairs, and finds the longest prefix match. The example inserts 'foo', 'bar', and 'foobar' with values, then uses LongestPrefix on 'foozip' to get 'foo' and panics if the result is incorrect. ```go // Create a tree r := iradix.New() r, _, _ = r.Insert([]byte("foo"), 1) r, _, _ = r.Insert([]byte("bar"), 2) r, _, _ = r.Insert([]byte("foobar"), 2) // Find the longest prefix match m, _, _ := r.Root().LongestPrefix([]byte("foozip")) if string(m) != "foo" { panic("should be foo") } ``` -------------------------------- ### Example: create and switch network namespaces Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/vishvananda/netns/README.md Go example demonstrating how to save the current network namespace, create a new one, list interfaces, and switch back. Must run as root. Note: the import path in the example is misspelled as 'github.com/vishvananada/netns'. ```go package main import ( "net" "runtime" "github.com/vishvananada/netns" ) func main() { // Lock the OS Thread so we don't accidentally switch namespaces runtime.LockOSThread() defer runtime.UnlockOSThread() // Save the current network namespace origns, _ := netns.Get() defer origns.Close() // Create a new network namespace newns, _ := netns.New() defer newns.Close() // Do something with tne network namespace ifaces, _ := net.Interfaces() fmt.Printf("Interfaces: %v\n", ifaces) // Switch back to the original namespace netns.Set(origns) } ``` -------------------------------- ### Set operations example using mapset Source: https://github.com/alibaba/pouch/blob/master/vendor/github.com/deckarep/golang-set/README.md Shows how to create sets, add elements, and perform union, difference, intersect, cardinality, and superset checks. Uses the mapset package. The output comments show expected results. ```go requiredClasses := mapset.NewSet() requiredClasses.Add("Cooking") requiredClasses.Add("English") requiredClasses.Add("Math") requiredClasses.Add("Biology") scienceSlice := []interface{}{"Biology", "Chemistry"} scienceClasses := mapset.NewSetFromSlice(scienceSlice) electiveClasses := mapset.NewSet() electiveClasses.Add("Welding") electiveClasses.Add("Music") electiveClasses.Add("Automotive") bonusClasses := mapset.NewSet() bonusClasses.Add("Go Programming") bonusClasses.Add("Python Programming") //Show me all the available classes I can take allClasses := requiredClasses.Union(scienceClasses).Union(electiveClasses).Union(bonusClasses) fmt.Println(allClasses) //Set{Cooking, English, Math, Chemistry, Welding, Biology, Music, Automotive, Go Programming, Python Programming} //Is cooking considered a science class? fmt.Println(scienceClasses.Contains("Cooking")) //false //Show me all classes that are not science classes, since I hate science. fmt.Println(allClasses.Difference(scienceClasses)) //Set{Music, Automotive, Go Programming, Python Programming, Cooking, English, Math, Welding} //Which science classes are also required classes? fmt.Println(scienceClasses.Intersect(requiredClasses)) //Set{Biology} //How many bonus classes do you offer? fmt.Println(bonusClasses.Cardinality()) //2 //Do you have the following classes? Welding, Automotive and English? fmt.Println(allClasses.IsSuperset(mapset.NewSetFromSlice([]interface{}{"Welding", "Automotive", "English"}))) //true ``` -------------------------------- ### Install Travis CI client and check versions Source: https://github.com/alibaba/pouch/blob/master/docs/test/debug_in_travis.md Install Travis CI command line client version 1.8.8 and verify Ruby and Travis versions. Prerequisite for generating an API token. ```shell # gem install travis -v 1.8.8 --no-rdoc --no-ri # ruby -v ruby 2.0.0p598 (2014-11-13) [x86_64-linux] # travis -v 1.8.8 ``` -------------------------------- ### Install PouchContainer on CentOS Source: https://github.com/alibaba/pouch/blob/master/INSTALLATION.md Installs the latest PouchContainer. On first install, you will be prompted to accept the GPG key. After installation, the 'pouch' group is created but no users are added. ```bash sudo yum install pouch ``` -------------------------------- ### pouch version output example Source: https://github.com/alibaba/pouch/blob/master/docs/commandline/pouch_version.md Example output of the pouch version command showing version details. ```bash $ pouch version GoVersion: go1.10.4 KernelVersion: 3.10.0-693.11.6.el7.x86_64 Os: linux Version: 1.0.0 APIVersion: 1.24 Arch: amd64 BuildTime: 2018-11-07T07:48:56.348129663Z GitCommit: ```