Skip to content

Build an image

func build turns a function project into a container image. It does not push anything to a registry by default (add --push to push the image), and it never deploys. For standard deployments, skip this separate build step: func deploy builds, pushes, and deploys in one command.

Requirements

  • An initialized function project containing func.yaml and source code. Create a project if needed.
  • A running Docker-compatible container engine, such as Docker or Podman, for containerized builders (pack or s2i).
  • Run commands from inside the function project directory (or use --path).

Build

Pass your registry: the registry host and your account namespace, for example ghcr.io/alice or docker.io/alice:

func build --registry <registry>
kn func build --registry <registry>

func names the image <registry>/<function-name>:latest and saves the registry in func.yaml, so later builds and deploys need no registry flag. You can also set the registry with FUNC_REGISTRY. The image stays in your container engine's local image store until you push it. If you previously set --image, see Set the image name yourself to return to registry-based naming.

Verify the image

Confirm the image exists (with Podman, use podman image ls):

docker image ls <registry>/<function-name>

A row with tag latest and an image ID confirms the build succeeded.

Other builders

func build supports --builder pack (Cloud Native Buildpacks, the default), --builder s2i (Source-to-Image), and --builder host, which builds with your local toolchain and needs no container engine. The host builder currently supports Go and Python functions. It writes the image to .func/build/oci in the project, not to the container engine, so docker image ls does not list it.

For remote on-cluster builds with Tekton, see Deploy a function — Build and deploy remotely. For all flags and builder options, see the func build reference.

Set the image name yourself

To choose the full image name instead of <registry>/<function-name>:latest, pass --image, for example --image ghcr.io/alice/my-image:v1. func saves it in the image: line in func.yaml, where it takes precedence over --registry and FUNC_REGISTRY on later builds and deploys. To return to registry-based naming, delete the image: line from func.yaml.

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.