Creating Functions from Existing Docker Images

Find out how to create functions from existing Docker images with OCI Functions.

You can create a new function definition in the OCI Functions server in different ways:

  • Using the Console, a CLI command, or an API operation to create a new function based on an existing Docker image that has already been pushed to the Docker registry (as described in this topic).
  • Using the single Fn Project CLI command fn deploy to build a new Docker image, push the image to the Docker registry, and create a new function based on the image in one step (as described in Creating and Deploying Functions).
  • Using Code Editor (see Creating Functions Using Code Editor).
  • Using pre-built functions (see Creating Functions Using Pre-Built Functions).

When creating a new function based on an existing Docker image, you specify function metadata to store in the OCI Functions server. For example, the maximum length of time the function is allowed to execute for.

The existing image on which you base a new function must be suitable for use with OCI Functions. Typically, to build and push a suitable image, you or somebody else will use Fn Project CLI commands and/or Docker CLI commands. For example, having written your function code and a func.yaml file containing function metadata (perhaps based on the template helloworld function and func.yaml created using fn init), you can:

  • Use fn build to build a new Docker image from the function.
  • Use docker push to push the image to the Docker registry.

With the image in the Docker registry, you can then use the Console, a CLI command, or an API operation to create a function based on the image, as described in this topic.

    1. Sign in to the Console as a functions developer.
    2. Open the navigation menu and click Developer Services. Under Functions, click Applications.
    3. Select the region you're using with OCI Functions.

      We recommend that you use the same region as the Docker registry that's specified in the Fn Project CLI context. See Creating an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure.

    4. Select the compartment specified in the Fn Project CLI context. See Creating an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure.

      The Applications page shows the applications defined in the compartment.

    5. Click the name of the application in which you want to create the function.

    6. Click the Create Function button, select Create from existing image, and specify the following details:
      • Name: A name for the new function. Avoid entering confidential information.
      • Repository: The repository in the OCI Container Registry in the current region that contains the image.
      • Image: The existing image in the OCI Container Registry repository in the current region. The image architecture must be compatible with the application's shape (see Specifying the Compute Architecture on Which to Run Functions).
      • Memory: The maximum amount of memory that the function can use while running.
      • Timeout: The maximum amount of time that the function can run for.
      • Enable provisioned concurrency: You can minimize any initial delays when invoking the function by specifying a minimum number of concurrent function invocations for which you want to have execution infrastructure constantly available.

        If you select this option, you enter a value for Provisioned concurrency units (PCUs) to specify the minimum number of concurrent function invocations. The actual PCUs value you enter must be a multiple of 10. If Memory is set to 256 MB, the PCUs value must be a multiple of 20; if Memory is set to 128 MB, the PCUs value must be a multiple of 40. The total number of PCUs available depends on the size of the function, the tenancy limit, and whether provisioned concurrency has been enabled for other functions in the tenancy. For more information about provisioned concurrency, see Reducing Initial Latency Using Provisioned Concurrency.

      • Tagging options: If you have permissions to create a resource, then you also have permissions to apply free-form tags to that resource. To apply a defined tag, you must have permissions to use the tag namespace. For more information about tagging, see Resource Tags. If you're not sure whether to apply tags, skip this option or ask an administrator. You can apply tags later.
    7. Select one of the following options:

      • To create the function in the OCI Functions server now, click Create. The new function is shown in the Console, in the list of functions in the application you selected.
      • To create the function later using Resource Manager and Terraform, click Save as stack to save the resource definition as a Terraform configuration. For more information about saving stacks from resource definitions, see Creating a Stack from a Resource Creation Page.
  • Using the Fn Project CLI

    Tip

    From time to time, new versions of the Fn Project CLI are released. We recommend you regularly check that the latest version is installed. For more information, see Steps to upgrade the Fn Project CLI.

    To use the Fn Project CLI to create a new function in the OCI Functions server from an existing Docker image that has already been pushed to the Docker registry:

    1. Log in to your development environment as a functions developer.

    2. In a terminal window, create a new function by entering:

      fn create function <app-name> <function-name> <image-name>

      where:

      • <app-name> is the name of an existing application in which to create the new function.
      • <function-name> is the name of the new function you want to create. Avoid entering confidential information.
      • <image-name> is the name of the existing image in the Docker registry on which to base the new function. The image architecture must be compatible with the application's shape (see Specifying the Compute Architecture on Which to Run Functions).

      For example:

      fn create function acmeapp acme-func phx.ocir.io/ansh81vru1zp/acme-repo/acme-func:0.0.3

      A new function is created in OCI Functions, based on the existing image and with the name you specified

    3. Verify that the new function has been created by entering:

      fn list functions <app-name>

      For example:

      $ fn list functions acme-app
      
      NAME            IMAGE
      acme-func       phx.ocir.io/ansh81vru1zp/acme-repo/acme-func:0.0.3

    Using the OCI CLI

    Use the oci fn function create command and required parameters to create a function:

    oci fn function create --application-id <application-ocid> --display-name <function-name> --memory-in-mbs <memory> [OPTIONS]

    For a complete list of flags and variable options for OCI CLI commands, see the Command Line Reference.

  • Run the CreateFunction operation to create a function.