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.

Console
CLI
API
Sign in to the Console as a functions developer.
In the Console, open the navigation menu and click Developer Services. Under Functions, click Applications.
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.

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.

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

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.

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.