Running functions

Running a function creates an OCI container image for your function before running the function in your local environment, but does not deploy the function to a cluster. This can be useful if you want to run your function locally for a testing scenario.

Prerequisites

  • You have a Docker daemon on your local machine. This is already provided if you have used the Quickstart installation.

Procedure

The run command builds an image for your function if required, and runs this image locally, instead of deploying it on a cluster.

func

Run the function locally by running the command inside the project directory. If you have not yet built the function you will need to provide the --registry flag:

  1. cd hello
  1. func run [--registry <registry>]

Note

The coordinates for the image registry can be configured through an environment variable (FUNC_REGISTRY) as well.

Using this command also builds the function if necessary.

You can force a rebuild of the image by running the command:

  1. func run --build

It is also possible to disable the build, by running the command:

  1. func run --build=false

kn func

Run the function locally, by running the command inside the project directory:

  1. cd hello
  1. kn func run

Using this command also builds the function if necessary.

You can force a rebuild of the image by running the command:

  1. kn func run --build

It is also possible to disable the build, by running the command:

  1. kn func run --build=false

You can verify that your function has been successfully run by using the invoke command and observing the output:

funckn func

  1. func invoke
  1. kn func invoke

Expected output

  1. Received response
  2. POST / HTTP/1.1 hello.default.127.0.0.1.sslip.io
  3. User-Agent: Go-http-client/1.1
  4. Content-Length: 25
  5. Accept-Encoding: gzip
  6. Content-Type: application/json
  7. K-Proxy-Request: activator
  8. X-Request-Id: 9e351834-0542-4f32-9928-3a5d6aece30c
  9. Forwarded: for=10.244.0.15;proto=http
  10. X-Forwarded-For: 10.244.0.15, 10.244.0.9
  11. X-Forwarded-Proto: http
  12. Body: