Skip to content

Running functions

Running a function starts it in your local environment without deploying it to a cluster. Containerized runs build an OCI image if needed; supported host-based runs use the local language toolchain instead. Neither path publishes an image by default. Local testing lets you exercise the handler before deployment.

Prerequisites

  • You have installed the CLI and created a function project.
  • For the containerized procedure below, you have a running Docker-compatible daemon and access to the builder images and dependencies. A registry prefix or explicit image name is needed when building the image; local run does not publish it.

You do not need a Knative cluster to run locally. If you want the experimental Go/Python host-based path instead, see Run without a container.

Procedure

For a containerized local test, explicitly select the pack builder. It builds the image if needed and runs it locally; it does not publish the image or deploy a Service.

  1. Open a terminal in the function project directory, for example hello:

    cd hello
    
  2. Start the function. Replace the registry prefix with your image-naming prefix. If the project already has a registry or image configured, you can omit --registry.

    func run --builder=pack --registry ghcr.io/your-username
    
    kn func run --builder=pack --registry ghcr.io/your-username
    

    FUNC_REGISTRY can also provide the registry prefix. This is an image name, not a request to push it. Access to private builder images and dependencies is separate from publishing credentials.

    For containerized runs, add --build to force a rebuild, or --build=false to skip building only when a usable image already exists.

  3. Wait for the command to report the local listening address. Leave this terminal running. In a second terminal, open the same project directory and explicitly invoke the local instance:

    func invoke --target=local
    
    kn func invoke --target=local
    

    Check the response and the running function's logs against your handler's expected behavior. Response bodies differ by language, template, and application code; cluster proxy headers are not expected for this local check.

  4. When you finish testing, press Ctrl+C in the terminal running the function. This stops the local process; it does not delete a deployed Service.

For request formats, test payloads, and alternate targets, consult the invoke section of the upstream command reference.

Run without a container

In Functions from Knative v1.24.0, the experimental host builder can run supported Go and Python projects as local processes, without first creating a container image or using a Docker daemon. Install the language toolchain and dependencies required by your generated project. Older Python layouts are not all supported; consult the matching Python template guide before using this route.

The run reference for Functions from Knative v1.24.0 describes this experimental path. Check the corresponding release reference for another installed CLI version. From the project directory, choose the host builder explicitly:

func run --builder=host
kn func run --builder=host

If the CLI prompts for an image registry, it is asking for project/image coordinates, not permission to publish an image. Keep the process running and use the same second-terminal local invocation check as above. A successful host run does not verify the container image or its cluster behavior.

If local testing fails

  • If startup fails, check the selected builder and its daemon or language-toolchain prerequisites. For a containerized run, retry without --build=false if no usable image has been built.
  • If invocation cannot connect, confirm that run is still active and use the address it reports rather than assuming port 8080 is available.
  • If the request reaches the handler but fails, compare its format with the selected template and inspect the local process logs. Redact secrets before sharing diagnostics.

After local testing, deploy the function. Local success does not establish cluster routing, registry pull access, or event delivery.

We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.