This topic describes how to create a custom container runtime function in the Function Compute console or by using Funcraft.

Create a function in the Function Compute console.

  1. Upload your function image to the image repository for the default instance.

    In the following example, the region of Function Compute is China (Shenzhen), and the name of the image repository is nodejs-express.

    cd /tmp
    git clone https://github.com/awesome-fc/custom-container-docs.git && cd custom-container-docs/nodejsexpress
    
    # Specify the ACR image address
    export IMAGE_NAME="your ACR image name"  # e.g. registry.cn-shenzhen.aliyuncs.com/fc-demo/nodejs-express:v0.2
    docker build -t $IMAGE_NAME .
    docker push $IMAGE_NAME
  2. Create a service and set permissions for it.
    1. In the Function Compute console, create a service. For more information, see Create a service.
    2. Assign the AliyunContainerRegistryReadOnlyAccess or AliyunContainerRegistryFullAccess permission policy to the service. For more information, see t1912132.html#task_2547896.
      In Function Compute, apply the preceding policies to the temporary account for the default instance in Alibaba Cloud Container Registry. Use the temporary account to upload images from your private image repository.
  3. Create a function.
    In this example, an event function is created. HTTP functions use similar parameter settings.
    1. Log on to the Function Compute console.
    2. In the top navigation bar, select your region.
    3. In the left-side navigation pane, click Service/Function.
    4. Click Create Function. On the page that appears, select Event Function and click Next.
    5. In the Configure Function step, set the parameters and click Create.
      create custom container
      Parameter Setting
      Service Name Select the service that you created in Step 2.
      Function Name Enter a custom function name.
      Runtime Select custom-container from the drop-down list.
      Instance Type Select a function instance type. Valid values:
      • Elastic
      • Performance

      For more information about instance types, see t1911640.html#concept_2542889.

      Container Image Enter the address of the container image.

      We recommend that you use the registry-vpc.Endpoint address for container images. An example address is registry-vpc.cn-hangzhou.aliyuncs.com/fc-demo/helloworld:v1beta1.

      Command Enter the startup command, for example, ["/code/myserver"].

      This parameter is optional. If you do not set this parameter, the ENTRYPOINT or CMD instruction included in the image is used.

      Args Enter additional parameters, for example, ["-arg1", "value1"].

      This parameter is optional. If you do not set this parameter, the CMD instruction included in the image is used.

      Memory Select the memory size used to run the function. The memory size cannot be less than 521 MB.
      Timeout Enter the timeout for requests.
      Single Instance Concurrency Enter the number of requests that can be concurrently processed by a single instance.

      For more information, see t1881063.html#concept_2259964.

      Listening Port Enter the port on which the server listens.

      This parameter is optional. Default value: 9000. You can change the listening port on this page, without needing to modify the image.

      After the function is created, you can view it in the function list of the corresponding service.

Use Funcraft to create a function

You can use Funcraft to build and upload container images and deploy functions with one click.

  1. Run the following commands to clone the custom-container-docs example:
    git clone https://github.com/awesome-fc/custom-container-docs.git
    cd custom-container-docs/nodejsexpress
  2. In template.yml, replace the value of the Image parameter with the address of your Alibaba Cloud Container Registry (ACR) image.
  3. Run the following commands to build the image and deploy the function:
    # Build the Docker image.
    fun build --use-docker
    
    # Deploy the function, push the image via the internet registry host (the function config uses the VPC registry for faster image pulling).
    fun deploy --push-registry acr-internet
    After the function is deployed, you can log on to the Function Compute console and view the function in the function list of the corresponding service.