### Test Case Setup and Cleanup Source: https://github.com/containerd/nerdctl/blob/main/docs/testing/tools.md Demonstrates defining a test case with setup, cleanup, command execution, and expected outcomes. The setup ensures volumes are created, and cleanup removes them. The command runs a container, and expected results include a specific exit code and error messages. ```go package main import ( "errors" testing "gotest.tools/v3/assert" "github.com/containerd/errdefs" "github.com/containerd/nerdctl/mod/tigron/expect" "github.com/containerd/nerdctl/mod/tigron/require" "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/mod/tigron/tig" "github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest" ) func TestMyThing(t *testing.T) { nerdtest.Setup() // Declare your test myTest := &test.Case{ Data: test.WithLabels(map[string]string{"sometestdata": "blah"}), Setup: func(data *test.Data, helpers test.Helpers){ helpers.Ensure("volume", "create", "foo") helpers.Ensure("volume", "create", "bar") }, Cleanup: func(data *test.Data, helpers test.Helpers){ helpers.Anyhow("volume", "rm", "foo") helpers.Anyhow("volume", "rm", "bar") }, Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { return helpers.Command("run", "--name", data.Identifier()+data.Labels().Get("sometestdata")) }, Expected: func(data test.Data, helpers test.Helpers) *test.Expected { return &test.Expected{ ExitCode: 1, Errors: []error{ errors.New("foobla"), errdefs.ErrNotFound, }, Output: func(stdout string, t tig.T) { assert.Assert(t, stdout == data.Labels().Get("sometestdata")) }, } }, } myTest.Run(t) } ``` -------------------------------- ### Install nerdctl using go install (Unrecommended) Source: https://github.com/containerd/nerdctl/blob/main/README.md An alternative method to install nerdctl using `go install`. This method is not recommended as it does not populate the version strings displayed by `nerdctl version`. ```bash go install github.com/containerd/nerdctl/v2/cmd/nerdctl ``` -------------------------------- ### Build nerdctl with make Source: https://github.com/containerd/nerdctl/blob/main/BUILDING.md Use 'make' to build nerdctl. 'sudo make install' is used to install the built binary. ```bash make sudo make install ``` -------------------------------- ### Install and run a container in rootless mode Source: https://github.com/containerd/nerdctl/blob/main/docs/faq.md Install the rootless mode tools and run a container. This allows using nerdctl as a non-root user. ```bash containerd-rootless-setuptool.sh install nerdctl run -d --name nginx -p 8080:80 nginx:alpine ``` -------------------------------- ### Install Lima and Run Nginx with Nerdctl on macOS Source: https://github.com/containerd/nerdctl/blob/main/README.md This sequence installs Lima, starts a Linux VM, and then runs an Nginx container using Nerdctl. ```bash brew install lima limactl start lima nerdctl run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine ``` -------------------------------- ### Compile and Install nerdctl from Source Source: https://github.com/containerd/nerdctl/blob/main/README.md Instructions for compiling and installing nerdctl locally using make. Ensure you have the minimum supported Go version as specified in go.mod. ```bash make && sudo make install ``` -------------------------------- ### Install Rootless Containerd Daemon Source: https://github.com/containerd/nerdctl/blob/main/docs/rootless.md Use this script to install and set up the rootless containerd service. It handles prerequisites and configures systemd user services. ```console $ containerd-rootless-setuptool.sh install [INFO] Checking RootlessKit functionality [INFO] Checking cgroup v2 [INFO] Checking overlayfs [INFO] Creating /home/testuser/.config/systemd/user/containerd.service ... [INFO] Installed containerd.service successfully. [INFO] To control containerd.service, run: `systemctl --user (start|stop|restart) containerd.service` [INFO] To run containerd.service on system startup, run: `sudo loginctl enable-linger testuser` [INFO] Use `nerdctl` to connect to the rootless containerd. [INFO] You do NOT need to specify $CONTAINERD_ADDRESS explicitly. ``` -------------------------------- ### Run Multi-platform Compose Demo Source: https://github.com/containerd/nerdctl/blob/main/examples/compose-multi-platform/README.md Execute this command to start the multi-platform Docker Compose services. Ensure QEMU is configured beforehand. ```bash nerdctl compose up -d ``` -------------------------------- ### Complete Test Example with Custom Command and Expectations Source: https://github.com/containerd/nerdctl/blob/main/mod/tigron/expect/doc.md A comprehensive example showing a custom bash command that writes to stderr and stdout, and expectations for exit code, stderr content, and stdout JSON structure. ```go package main import ( "testing" "errors" "github.com/containerd/nerdctl/mod/tigron/tig" "github.com/containerd/nerdctl/mod/tigron/test" "github.com/containerd/nerdctl/mod/tigron/expect" ) type Thing struct { Name string } func TestMyThing(t *testing.T) { // Declare your test myTest := &test.Case{} // Attach a command to run myTest.Command = test.Custom("bash", "-c", "--", ">&2 echo thing; echo '{\"Name\": \"out\"}'; exit 42;") // Set your expectations myTest.Expected = test.Expects( expect.ExitCodeGenericFail, []error{errors.New("thing")}, expect.All( expect.Contains("out"), expect.DoesNotContain("something"), expect.JSON(&Thing{}, func(obj *Thing, t tig.T) { assert.Equal(t, obj.Name, "something") }), ), ) // Run it myTest.Run(t) } ``` -------------------------------- ### Basic nerdctl compose Usage Source: https://github.com/containerd/nerdctl/blob/main/docs/compose.md Demonstrates common commands for starting and stopping services with nerdctl compose. Ensure nerdctl version 0.8 or higher is installed. ```console $ nerdctl compose up -d $ nerdctl compose down ``` -------------------------------- ### Install rootless containerd Source: https://github.com/containerd/nerdctl/blob/main/README.md Install rootless containerd using the provided script. This is a prerequisite for running containers in rootless mode. ```bash $ containerd-rootless-setuptool.sh install ``` -------------------------------- ### Start Services with Nerdctl Compose Source: https://github.com/containerd/nerdctl/blob/main/docs/command-reference.md Use `nerdctl compose up` to create and start containers defined in a Compose file. Options like `-d` for detached mode and `--build` for image building are available. ```bash nerdctl compose up -d ``` -------------------------------- ### Install Stargz Snapshotter Source: https://github.com/containerd/nerdctl/blob/main/docs/rootless.md Installs the Stargz Snapshotter, which enables lazy-pulling of images for faster startup times. This is beneficial for large images. ```console $ containerd-rootless-setuptool.sh install-stargz ``` -------------------------------- ### Install Development Tools Source: https://github.com/containerd/nerdctl/blob/main/mod/tigron/README.md Run this script to set up development tools for Tigron. Choose the script appropriate for your operating system. ```shell ./hack/dev-setup-linux.sh ``` ```shell # Or # ./hack/dev-setup-macos.sh ``` ```shell make install-dev-tools ``` -------------------------------- ### Basic Test Case Setup with Expectations Source: https://github.com/containerd/nerdctl/blob/main/mod/tigron/expect/doc.md Demonstrates the fundamental structure of a test case using `test.Case` and `test.Expects` to define a command and its expected outcome. ```go package main import ( "testing" "github.com/containerd/nerdctl/mod/tigron/test" ) func TestMyThing(t *testing.T) { // Declare your test myTest := &test.Case{} // Attach a command to run myTest.Command = test.Custom("ls") // Set your expectations myTest.Expected = test.Expects(expect.ExitCodeSuccess, nil, nil) // Run it myTest.Run(t) } ``` -------------------------------- ### Start containerd and cvmfs-snapshotter Services Source: https://github.com/containerd/nerdctl/blob/main/docs/cvmfs.md Launch the `containerd` and `cvmfs-snapshotter` services using systemctl to enable the snapshotter functionality. ```console $ systemctl start containerd cvmfs-snapshotter ``` -------------------------------- ### Prepare Environment for Cosign Source: https://github.com/containerd/nerdctl/blob/main/docs/cosign.md Create a sample Dockerfile and build a container image. Ensure cosign is installed and its executable is in your PATH. Generate a key-pair for signing and export the COSIGN_PASSWORD environment variable. ```shell # Create a sample Dockerfile $ cat < /usr/share/nginx/html/index.html ``` -------------------------------- ### Install IPFS Daemon in Rootless Mode Source: https://github.com/containerd/nerdctl/blob/main/docs/ipfs.md Use this command to install and initialize the IPFS daemon when running containerd in rootless mode. Remember to set the IPFS_PATH environment variable as instructed. ```bash containerd-rootless-setuptool.sh --install-ipfs --init ``` -------------------------------- ### Run WordPress + MariaDB with Nerdctl Compose Source: https://github.com/containerd/nerdctl/blob/main/examples/compose-wordpress/README.md Use this command to start a WordPress and MariaDB stack. Remember to substitute your password in the docker-compose.yaml file. ```bash nerdctl compose up ``` -------------------------------- ### nerdctl run with Binary Shim Logger Source: https://github.com/containerd/nerdctl/blob/main/docs/command-reference.md Example of running a container with a binary shim logger, specifying the LogURI with a scheme. ```bash nerdctl run -d --log-driver binary:///usr/bin/ctr-journald-shim docker.io/library/hello-world:latest ``` -------------------------------- ### Example Dockerfile for Debugging Source: https://github.com/containerd/nerdctl/blob/main/docs/builder-debug.md A simple Dockerfile used to demonstrate interactive debugging. It defines build stages and echo commands. ```Dockerfile FROM busybox AS build1 RUN echo a > /a RUN echo b > /b RUN echo c > /c ``` -------------------------------- ### Start IPFS registry server Source: https://github.com/containerd/nerdctl/blob/main/docs/ipfs.md Run this command in the background to allow `nerdctl build` to pull images from IPFS. The `--ipfs` flag has been removed since v1.2.0. ```bash nerdctl ipfs registry serve & ``` -------------------------------- ### Example nerdctl.toml Configuration Source: https://github.com/containerd/nerdctl/blob/main/docs/config.md This TOML snippet shows a sample configuration for `nerdctl.toml`. It includes settings for debugging, containerd address and namespace, snapshotter, cgroup manager, certificate directories, and experimental features. ```toml # This is an example of /etc/nerdctl/nerdctl.toml . # Unrelated to the daemon's /etc/containerd/config.toml . debug = false debug_full = false address = "unix:///run/k3s/containerd/containerd.sock" namespace = "k8s.io" snapshotter = "stargz" cgroup_manager = "cgroupfs" hosts_dir = ["/etc/containerd/certs.d", "/etc/docker/certs.d"] experimental = true userns_remap = "" dns = ["8.8.8.8", "1.1.1.1"] dns_opts = ["ndots:1", "timeout:2"] dns_search = ["example.com", "example.org"] selinux_enabled= true ``` -------------------------------- ### Install nerdctl on Kind Worker Node Source: https://github.com/containerd/nerdctl/blob/main/examples/nerdctl-ipfs-registry-kubernetes/ipfs/README.md Installs `nerdctl` on a `kind` worker node by downloading and extracting the binary. Requires `docker exec` to run commands inside the container. ```bash docker exec -it kind-worker /bin/bash (kind-worker)# NERDCTL_VERSION=0.23.0 (kind-worker)# curl -fsSL --proto '=https' --tlsv1.2 --output /tmp/nerdctl.tgz https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz (kind-worker)# tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin/ ``` -------------------------------- ### Install BuildKit (OCI worker, Rootless) Source: https://github.com/containerd/nerdctl/blob/main/docs/build.md Installs the BuildKit daemon with the OCI worker for rootless environments. Note that this configuration prevents BuildKit from accessing images managed by containerd, including those previously built with `nerdctl build`. ```bash $ containerd-rootless-setuptool.sh install-buildkit ``` -------------------------------- ### Start Interactive Dockerfile Debugging Source: https://github.com/containerd/nerdctl/blob/main/docs/builder-debug.md Initiate an interactive debugging session for a Dockerfile. Specify the path to the build context. ```bash $ nerdctl builder debug /path/to/context ``` -------------------------------- ### Systemd Unit File for Nerdctl IPFS Registry Source: https://github.com/containerd/nerdctl/blob/main/docs/ipfs.md This is an example systemd unit file for `nerdctl ipfs registry serve`. It uses `EnvironmentFile` to configure the registry's behavior, such as the listening port. ```systemd [Unit] Description=nerdctl ipfs registry serve [Service] EnvironmentFile-=/run/nerdctl-ipfs-registry-serve/env ExecStart=nerdctl ipfs registry serve [Install] WantedBy=default.target ``` -------------------------------- ### Enable BuildKit service (Rootful) Source: https://github.com/containerd/nerdctl/blob/main/docs/build.md Enables and starts the BuildKit service for rootful environments. This command assumes systemd is used for service management. ```bash $ sudo systemctl enable --now buildkit ``` -------------------------------- ### Cleanup Routine Example Source: https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md Implement cleanup logic using a function and `t.Cleanup`. Call the cleanup routine before any other operations to handle potential leftovers from previous runs. ```go tearDown := func(){ // Do some cleanup } tearDown() t.Cleanup(tearDown) ``` -------------------------------- ### Configure ECR Credential Helper Source: https://github.com/containerd/nerdctl/blob/main/docs/registry.md Set up `docker-credential-ecr-login` for more secure authentication with ECR. This requires installing the helper and configuring `~/.docker/config.json` and `~/.aws/credentials`. ```json { "credHelpers": { "public.ecr.aws": "ecr-login", ".dkr.ecr..amazonaws.com": "ecr-login" } } ``` -------------------------------- ### Compose File with IPFS Image Reference Source: https://github.com/containerd/nerdctl/blob/main/docs/ipfs.md Example `docker-compose.yml` demonstrating how to specify an image directly from IPFS using the `ipfs://` prefix. ```yaml version: "3.8" services: ubuntu: image: ipfs://bafkreicq4dg6nkef5ju422ptedcwfz6kcvpvvhuqeykfrwq5krazf3muze command: echo hello ``` -------------------------------- ### Prepare Kind Worker for IPFS Image Import Source: https://github.com/containerd/nerdctl/blob/main/examples/nerdctl-ipfs-registry-kubernetes/ipfs-cluster/README.md Installs nerdctl on a Kind worker node and sets up the environment for IPFS image operations. Requires containerd >= v1.5.8. ```bash docker exec -it kind-worker /bin/bash (kind-worker)# NERDCTL_VERSION=0.23.0 (kind-worker)# curl -o /tmp/nerdctl.tgz -fsSL --proto '=https' --tlsv1.2 https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz (kind-worker)# tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin/ ``` -------------------------------- ### Interactive Debugging Session Example Source: https://github.com/containerd/nerdctl/blob/main/docs/builder-debug.md Demonstrates an interactive debugging session using `nerdctl builder debug`. Includes setting breakpoints, continuing execution, and inspecting files within the build environment. ```console $ nerdctl builder debug --image=ubuntu:22.04 /tmp/ctx/ WARN[2022-05-17T10:15:48Z] using host network as the default#1 [internal] load .dockerignore #1 transferring context: 2B done #1 DONE 0.1s #2 [internal] load build definition from Dockerfile #2 transferring dockerfile: 108B done #2 DONE 0.1s #3 [internal] load metadata for docker.io/library/busybox:latest INFO[2022-05-17T10:15:51Z] debug session started. type "help" for command reference. Filename: "Dockerfile" => 1| FROM busybox AS build1 2| RUN echo a > /a 3| RUN echo b > /b 4| RUN echo c > /c (buildg) break 3 (buildg) breakpoints [0]: line: Dockerfile:3 [on-fail]: breaks on fail (buildg) continue #3 DONE 3.1s #4 [1/4] FROM docker.io/library/busybox@sha256:d2b53584f580310186df7a2055ce3ff83cc0df6caacf1e3489bff8cf5d0af5d8 #4 resolve docker.io/library/busybox@sha256:d2b53584f580310186df7a2055ce3ff83cc0df6caacf1e3489bff8cf5d0af5d8 0.0s done #4 sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 0B / 772.81kB 0.2s #4 sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 0B / 772.81kB 5.3s #4 sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 0B / 772.81kB 10.4s #4 sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 772.81kB / 772.81kB 11.4s done #4 extracting sha256:50e8d59317eb665383b2ef4d9434aeaa394dcd6f54b96bb7810fdde583e9c2d1 0.1s done #4 DONE 20.2s #5 [2/4] RUN echo a > /a #5 DONE 0.1s Breakpoint[0]: reached line: Dockerfile:3 Filename: "Dockerfile" 1| FROM busybox AS build1 2| RUN echo a > /a *=> 3| RUN echo b > /b 4| RUN echo c > /c (buildg) exec --image sh # ls /debugroot/ a b bin dev etc home proc root tmp usr var # cat /debugroot/a /debugroot/b a b # (buildg) quit ``` -------------------------------- ### Compare pull speed with CernVM-FS Snapshotter Source: https://github.com/containerd/nerdctl/blob/main/docs/cvmfs.md This example demonstrates the speed difference when pulling an image with and without the CernVM-FS snapshotter. The output shows the pull time and resulting image size. ```console $ nerdctl --snapshotter cvmfs-snapshotter pull clelange/cms-higgs-4l-full:latest docker.io/clelange/cms-higgs-4l-full:latest: resolved |++++++++++++++++++++++++++++++++++++++| manshift-sha256:b8acbe80629dd28d213c03cf1ffd3d46d39e573f54215a281fabce7494b3d546: done |++++++++++++++++++++++++++++++++++++++| config-sha256:89ef54b6c4fbbedeeeb29b1df2b9916b6d157c87cf1878ea882bff86a3093b5c: done |++++++++++++++++++++++++++++++++++++++| elapsed: 4.7 s total: 19.8 K (4.2 KiB/s) $ nerdctl images REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE clelange/cms-higgs-4l-full latest b8acbe80629d 20 seconds ago linux/amd64 0.0 B 4.3 GiB ``` ```console $ nerdctl pull clelange/cms-higgs-4l-full:latest docker.io/clelange/cms-higgs-4l-full:latest: resolved |++++++++++++++++++++++++++++++++++++++| manshift-sha256:b8acbe80629dd28d213c03cf1ffd3d46d39e573f54215a281fabce7494b3d546: exists |++++++++++++++++++++++++++++++++++++++| config-sha256:89ef54b6c4fbbedeeeb29b1df2b9916b6d157c87cf1878ea882bff86a3093b5c: exists |++++++++++++++++++++++++++++++++++++++| layer-sha256:e8114d4b0d10b33aaaa4fbc3c6da22bbbcf6f0ef0291170837e7c8092b73840a: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:a3eda0944a81e87c7a44b117b1c2e707bc8d18e9b7b478e21698c11ce3e8b819: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:8f3160776e8e8736ea9e3f6c870d14cd104143824bbcabe78697315daca0b9ad: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:22a5c05baa9db0aa7bba56ffdb2dd21246b9cf3ce938fc6d7bf20e92a067060e: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:bfcf9d498f92b72426c9d5b73663504d87249d6783c6b58d71fbafc275349ab9: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:0563e1549926b9c8beac62407bc6a420fa35bcf6f9844e5d8beeb9165325a872: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:6fff5fd7fb4eeb79a1399d9508614a84191d05e53f094832062d689245599640: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:25c39bfa66e1157415236703abc512d06cc1db31bd00fe8c3030c6d6d249dc4e: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:3cc0a0eb55eb3fb7ef0760c6bf1e567dfc56933ba5f11b5415f89228af751b72: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:a8850244786303e508b94bb31c8569310765e678c9c73bf1199310729209b803: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:32cdf5fc12485ac061347eb8b5c3b4a28505ce8564a7f3f83ac4241f03911176: done |++++++++++++++++++++++++++++++++++++++| elapsed: 181.8s total: 4.3 Gi (24.2 MiB/s) $ nerdctl images REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE clelange/cms-higgs-4l-full latest b8acbe80629d 4 minutes ago linux/amd64 9.0 GiB 4.3 GiB ``` -------------------------------- ### Custom Test Manager for Advanced Expectations Source: https://github.com/containerd/nerdctl/blob/main/mod/tigron/expect/doc.md Use a custom `test.Manager` when you need to access data set during the `Setup` phase within your `Expected` function for more refined verifications. This example demonstrates setting a label in `Setup` and asserting its value in the `Output` check. ```go package main import ( "errors" "testing" "gotest.tools/v3/assert" "github.com/containerd/nerdctl/mod/tigron/tig" "github.com/containerd/nerdctl/mod/tigron/test" ) func TestMyThing(t *testing.T) { // Declare your test myTest := &test.Case{} myTest.Setup = func(data test.Data, helpers test.Helpers){ // Do things... // ... // Save this for later data.Labels().Set("something", "lalala") } // Attach a command to run myTest.Command = test.Custom("somecommand") // Set your fully custom expectations myTest.Expected = func(data test.Data, helpers test.Helpers) *test.Expected { // With a custom Manager you have access to both the test.Data and test.Helpers to perform more // refined verifications. return &test.Expected{ ExitCode: 1, Errors: []error{ errors.New("foobla"), }, Output: func(stdout string, t tig.T) { t.Helper() // Retrieve the data that was set during the Setup phase. assert.Assert(t, stdout == data.Labels().Get("sometestdata")) }, } } // Run it myTest.Run(t) } ``` -------------------------------- ### Create a Sample Dockerfile Source: https://github.com/containerd/nerdctl/blob/main/docs/notation.md This snippet creates a basic Dockerfile for building a sample container image. ```shell cat < ${DIR_LOCATION}/bootstrap.yaml ``` -------------------------------- ### Create Kind Cluster and Apply Manifests Source: https://github.com/containerd/nerdctl/blob/main/examples/nerdctl-ipfs-registry-kubernetes/ipfs/README.md Commands to create a `kind` cluster with a specific Kubernetes version and apply the necessary configuration files for IPFS image sharing. ```bash cat < /tmp/kindconfig.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker EOF kind create cluster --image=kindest/node:v1.25.2 --config=/tmp/kindconfig.yaml ./bootstrap.yaml.sh > ./bootstrap.yaml kubectl apply -f . ``` -------------------------------- ### Build and output to a local directory with BuildKit Source: https://github.com/containerd/nerdctl/blob/main/README.md Build an image using BuildKit and output the result to a local directory. ```bash # nerdctl build -o type=local,dest=. /some-dockerfile-directory ``` -------------------------------- ### Run Integration Tests in a Container Source: https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md Build a Docker image with the integration tests and run them in a privileged container. Ensure you have Docker installed. ```bash docker build -t test-integration --target test-integration . docker run -t --rm --privileged test-integration ``` -------------------------------- ### Run Unit Tests Source: https://github.com/containerd/nerdctl/blob/main/docs/testing/README.md Execute basic unit tests using the `make test` command. This task must be run on a supported OS (linux, windows, or freebsd). ```bash # This will run basic unit testing make test ``` -------------------------------- ### Run container with all AMD GPUs Source: https://github.com/containerd/nerdctl/blob/main/docs/gpu.md Exposes all available AMD GPUs to the container. Ensure AMD Container Toolkit and drivers are installed. ```bash nerdctl run -it --rm --gpus=all rocm/rocm-terminal rocm-smi ``` -------------------------------- ### Run container with all NVIDIA GPUs Source: https://github.com/containerd/nerdctl/blob/main/docs/gpu.md Exposes all available NVIDIA GPUs to the container. Ensure NVIDIA Container Toolkit and drivers are installed. ```bash nerdctl run -it --rm --gpus all nvidia/cuda:12.3.1-base-ubuntu20.04 nvidia-smi ``` -------------------------------- ### Custom Environment Checks with Info and Version Source: https://github.com/containerd/nerdctl/blob/main/docs/testing/tools.md Use `nerdtest.Info` for custom checks against `nerdctl info` output and `nerdtest.SociVersion`, `nerdtest.ContainerdVersion`, `nerdtest.CNIFirewallVersion` for specific version requirements. ```go nerdtest.Info(func(info dockercompat.Info) error { ... }) // `nerdctl info` should satisfy custom conditions nerdtest.SociVersion("0.10.0") // SOCI snapshotter version check nerdtest.ContainerdVersion("2.0.0") // containerd version check nerdtest.CNIFirewallVersion("1.7.1") // CNI firewall plugin version check ``` -------------------------------- ### Build and Push Multi-platform Images (Option 1) Source: https://github.com/containerd/nerdctl/blob/main/docs/multi-platform.md Build a container image for multiple platforms and push it directly. This method uses the --output flag with type=image and push=true. ```bash nerdctl build --platform=amd64,arm64 --output type=image,name=example.com/foo:latest,push=true . ``` -------------------------------- ### Run container with Stargz Snapshotter Source: https://github.com/containerd/nerdctl/blob/main/docs/stargz.md Use the `--snapshotter=stargz` flag with `nerdctl run` to leverage lazy-pulling for faster container startup. This is useful for images pre-converted to Stargz format. ```console # nerdctl --snapshotter=stargz run -it --rm ghcr.io/stargz-containers/fedora:30-esgz ``` -------------------------------- ### Pre-defined Requirements for Tests Source: https://github.com/containerd/nerdctl/blob/main/mod/tigron/require/doc.md These are examples of built-in requirements that can be used to enforce test environment conditions. They cover OS specificity and binary availability. ```go require.Windows // a test runs only on Windows require.Linux // a test runs only on Linux test.Darwin // a test runs only on Darwin test.OS(name string) // a test runs only on the OS `name` require.Binary(name string) // a test requires the binary `name` to be in the PATH require.Not(req Requirement) // a test runs only if the opposite of the requirement `req` is fulfilled require.All(req ...Requirement) // a test runs only if all requirements are fulfilled ``` -------------------------------- ### Inspecting Raw OCI Container Configuration Source: https://github.com/containerd/nerdctl/blob/main/README.md Inspect the raw OCI configuration of a container in native mode. This provides low-level details about the container's setup. ```bash nerdctl container inspect --mode=native ``` -------------------------------- ### Pull and Up Services with Nerdctl Compose Source: https://github.com/containerd/nerdctl/blob/main/docs/cosign.md After pushing, pull the images and bring up the services using `nerdctl compose pull` and `nerdctl compose up`. The `env "COSIGN_PASSWORD=$COSIGN_PASSWORD"` is a workaround for rootful nerdctl. Commands for running a specific service and cleaning up are also provided. ```shell # ensure built images are removed and pull is performed. $ sudo nerdctl compose down $ sudo env "COSIGN_PASSWORD=$COSIGN_PASSWORD" nerdctl compose --experimental=true pull $ sudo env "COSIGN_PASSWORD=$COSIGN_PASSWORD" nerdctl compose --experimental=true up $ sudo env "COSIGN_PASSWORD=$COSIGN_PASSWORD" nerdctl compose --experimental=true run svc0 -- echo "hello" # clean up compose resources. $ sudo nerdctl compose down ```