All Products
Search
Document Center

Function Compute:Create a custom container function

Last Updated:Jun 26, 2026

If the built-in runtimes in Function Compute do not meet your business requirements, you can create a custom container function. This topic describes how to create a custom container function in the Function Compute console or by using the Serverless Devs tool.

Usage notes

  • To create a custom container function in Function Compute, you must use an Alibaba Cloud Container Registry image from the same region and Alibaba Cloud account. If you build images on computers with Apple silicon or other ARM-based architectures, you must specify the build platform as linux/amd64. Example: docker build --platform linux/amd64 -t $IMAGE_NAME ..

  • Function Compute resolves domain names for Alibaba Cloud Container Registry Enterprise Edition images using either the default resolution of the configured VPC or the access IP addresses automatically resolved by Configure VPC access control.

    • Scenario 1: If the Default Resolution identifier is not displayed for any IP address on the Access Control page of the instance, all IP addresses in the Access IP list are automatically resolved by Alibaba Cloud DNS PrivateZone. In this case, any VPC configuration can be used.

      image

    • Scenario 2: If, on the Access Control page of an ACR Enterprise Edition instance, the Access IP list contains an IP address marked with Default Resolution that is the default resolution IP address of a VPC, you can select only the first VPC, as shown in the following figure.

      image

  • When you use an Enterprise Edition instance, you can only select non-accelerated images. Each time you update a function's image configuration, the system generates a new accelerated image based on the latest original image you selected, overwriting any existing accelerated image. Do not delete the original or accelerated images, or function invocations will fail.

  • Ensure that you update your function promptly if the image configured for it changes. Otherwise, function invocations will fail.

    • Ensure that the original image exists. Otherwise, the function enters a Failed state and cannot be invoked. Although functioncompute caches your function to reduce cold start times, invocations still require the original image.

    • Ensure that the image used in your function is not overwritten with a different digest. If this happens, you must redeploy your function with the latest image information. Function Compute records both the tag and the digest of the image version you select during function creation and updates. If the image tag is updated elsewhere to point to a new digest, function invocations will fail.

Prerequisites

Create a function in the console

  1. Log on to the Function Compute console. In the navigation pane on the left, choose Function Management > Functions.

  2. In the top navigation bar, select a region. On the Functions page, click Create Function.

  3. In the dialog box that appears, select the GPU Function type based on your scenario, and then click Create GPU Function.

  4. On the Create GPU Function page, configure the following parameters and click Create.

    • Basic Configurations: Enter a Function Name. The name must be unique within the same Alibaba Cloud account and region, and must follow the naming conventions.

    • Scaling Policy: Select an instance type. You cannot use provisioned and on-demand instances at the same time. You cannot change the instance type after creating the function.

      • On-demand instances

        Configuration Item

        Description

        Example

        Instance Type

        Select On-demand Instance. Instances scale automatically based on request volume and are released when there are no requests. You are billed for what you use.

        On-demand Instance

        GPU Card Type

        Select a GPU card type.

        Ada series

        Specifications

        Set the GPU Memory, vCPU, Memory, and Disk specifications for the function based on your business needs. After you set the specifications, the usage of each resource is calculated by multiplying the specification by the duration of use.

        Note
        • All directories on the disk are writable. The disk space is shared.

        • The disk is tied to the instance lifetime of the underlying function. When the system reclaims the instance, data on the disk is lost. If you need persistent storage, you can mount a NAS file system or an OSS bucket.

        • GPU Memory: 48 GB

        • vCPU: 8 vCPU

        • Memory: 64 GB

        • Disk: 512 MB (not billed, Function Compute provides a free quota of 10 GB disk space)

        Minimum Instances

        If your business is latency-sensitive, after you select Elastic Instance, we recommend that you set the minimum number of instances to 1 or greater to lock resources in advance and reduce cold start latency.

        Note

        After you set Minimum Instances to 1 or more, if no elastic policy for the minimum number of instances is configured or if no elastic policy is active for a period, the current minimum number of instances is the value you set here.

        If multiple elastic policies are configured, the system calculates the Minimum Number Of Instances required when each policy is triggered. The system then uses the highest value among the active policies as the current Minimum Number Of Instances.

        1

        Concurrency Per Instance

        You can configure multiple concurrent requests for a single GPU function instance. This means a single instance can process multiple requests simultaneously.

      • Provisioned instances

        Configuration Item

        Description

        Example

        Instance Type

        Select Provisioned Instance. Instances are allocated to the function from a pre-purchased provisioned resource pool.

        Provisioned instances are recommended for scenarios where predictable costs, low latency, and high resource utilization are important to ensure business stability.

        Provisioned Instance

        Provisioned Resource Pool

        A provisioned resource pool is a pool of provisioned instances that can be allocated to the target function. If your provisioned resource pool has insufficient capacity, click Scale-out in the Actions column and follow the on-screen instructions to expand it. For more information, see Resident resource pools (subscription).

        • Provisioned Resource Pool: fc-pool-****

        • GPU Card Type: Ada

        Specifications

        Set the GPU Memory, vCPU, Memory, and Disk specifications for the function based on your business needs. After you set the specifications, the usage of each resource is calculated by multiplying the specification by the duration of use. For more information, see Billing overview.

        Note
        • All directories on the disk are writable. The disk space is shared.

        • The disk is tied to the instance lifetime of the underlying function. When the system reclaims the instance, data on the disk is lost. If you need persistent storage, you can mount a NAS file system or an OSS bucket.

        GPU Memory: 48 GB

        vCPU: 8 vCPU

        Memory: 64 GB

        Disk: 512 MB (not billed, Function Compute provides a free quota of 10 GB disk space)

        Number Of Provisioned Instances

        Allocate a number of provisioned instances to the target function based on the resources available in the provisioned resource pool.

        1

        Concurrency Per Instance

        You can configure multiple concurrent requests for a single GPU function instance. This means a single instance can process multiple requests simultaneously. For more information, see Configure instance concurrency.

        20

    • Code: Configure the function's runtime environment and code-related settings.

      Parameter

      Description

      Example

      Runtime

      • Use sample images: Select a sample image provided by Function Compute to quickly deploy a custom container function. You must select a target image from the list under the Container Image parameter.

      • Use container registry images: Click Select ACR image under the Container Image parameter. In the Select container image panel, select the Container registry instance and Image repository. Then, find the target image in the image list below and click Select in the Actions column.

      Note
      • You cannot create a function using a public image from an Alibaba Cloud Container Registry instance that belongs to another account.

      • Ensure that you update your function promptly if the image configured for it changes. Otherwise, function invocations will fail. For more information,

      • When you use an Enterprise Edition instance, you can only select non-accelerated images. Do not delete the original or accelerated images, or function invocations will fail..

      • Enterprise Edition instances do not support image addresses in a custom domain name format.

      • You cannot create functions by using images from repositories in which image acceleration is enabled in index-only mode. This applies to Container Registry Enterprise Edition (Standard and Advanced) instances.

      • After Alibaba Cloud Container Registry introduced the index-only mode feature, you can no longer create functions using images from newly created repositories in Enterprise Edition (Basic) instances if image acceleration is enabled. However, you can still use images from existing accelerated repositories in these instances.

      Custom Container

      Container Image

      Select the target image.

      SpringBoot Web App Sample Image

      Startup Command

      The startup command for the program. If not specified, Function Compute uses the Entrypoint or CMD from the image by default.

      None

      Listening Port

      The port on which the HTTP server in your code listens.

      9000

      Execution Timeout Period

      Set the timeout period. The Execution Timeout Period defaults to 60 seconds, with a maximum of 86,400 seconds.

      60

    • Instance Prefetch: In AI inference scenarios, you can configure instance prefetch to pre-warm the model. This eliminates the cold start latency for the first request.

      Configuration Item

      Description

      Example

      Instance Prefetch

      Instance Prefetch

      Configure an Initializer hook to pre-warm the instance and optimize cold starts. The hook runs a specified script or calls an interface to load the model after the function instance starts but before it processes requests.

      Enabled

      Timeout

      Set the timeout period for the Initializer hook.

      60

      Prefetch Program Type

      You can configure two types of Initializer hooks to pre-warm the model: Execute Instruction and Invoke Code.

      Execute Instruction

      Instruction Content

      Configure the content of the instruction to execute. You can use custom shell implementations, such as /bin/bash, /bin/sh, /bin/csh, and /bin/zsh. Make sure the function's runtime environment supports the selected shell.

    • Permissions, Network, and Storage:Configure function execution role, network, and storage mounting.

      Configuration Item

      Description

      Example

      Execution Role

      Function Compute assumes this RAM role to generate temporary credentials for accessing Alibaba Cloud resources and passes them to the code. For more information, see 。

      mytestrole

      VPC Access

      Allows the function to access resources within a VPC. For more information, see 。

      Enable

      VPC

      VPC AccessRequired when VPC Access is set to Yes. Create a new VPC or select the VPC ID to access from the drop-down list.

      fc.auto.create.vpc.1632317****

      vSwitch

      VPC AccessRequired when VPC Access is set to Yes. Create a new vSwitch or select a vSwitch ID from the drop-down list.

      fc.auto.create.vswitch.vpc-bp1p8248****

      Security Group

      VPC AccessRequired when VPC Access is set to Yes. Create a new security group or select from the drop-down listSecurity Group。

      fc.auto.create.SecurityGroup.vsw-bp15ftbbbbd****

      Allow Default NIC to Access Internet

      Select Yes or No to allow the function to access the Internet through the default network interface.

      Important

      When you use the fixed public IP address feature, you must disable Allow Function to Access the Internet via Default NIC. Otherwise, the configured fixed public IP address does not take effect. For more information, see 。

      Enable

      NAS Mounting

      Mount Configure a NAS file system to the function for persistent storage of data shared among functions, such as models shared by multiple inference functions.

      If you select Automatic Configuration, the system uses the existing general-purpose NAS file system named Alibaba-Fc-V3-Component-Generated by default. If no eligible NAS file system exists under the current account, the system automatically creates one.

      Enable

      OSS Mounting

      Mount OSS to the function for persistent storage of logs, business files, and more. For more information, see 。

      Enable

    • Logging and Tracing

      Configuration Item

      Description

      Example

      Log Feature

      Configure this option to persist function execution logs to Log Service, facilitating code debugging, troubleshooting, and data analysis. For more information, see 。

      • Automatic Configuration: Automatically selects the Log Project that starts with serverless-<region_id>.

        Only one such Log Project is created per region. If the system detects an existing Log Project in the current region, it is used directly.

      • Custom Configuration: You must manually specify the target Log Project and Logstore.

      Enable

    • Other Configurations

      Configuration Item

      Description

      Example

      Timezone

      Select the timezone for the function. After you set the timezone, an environment variable TZ is automatically added with the value set to the target timezone.

      UTC

      Tags

      Set Configure tags for the function to facilitate group management. You must set both the tag key and tag value.

      key : value

      Resource Group

      Select the Configure resource groups for the function to manage functions by group.

      Default Resource Group

      Environment Variables

      Use environment variables to flexibly adjust the function behavior without modifying code.

      {
          "BUCKET_NAME": "MY_BUCKET",
          "TABLE_NAME": "MY_TABLE"
      }

    After you create the function, you can view and update it on the Function List page.

Note

When you update the function, you can change the configured listener port, but you cannot add or remove ports. If you configured a listener port when you created the function, the system retains the original port configuration if you do not specify a listener port during an update.

Create a function with Serverless Devs

You can use Serverless Devs to build and push container images and deploy functions with a single command flow.

  1. Run the following command to initialize a project.

    sudo s init

    Follow the prompts to select an Alibaba Cloud account, a custom image template, and a programming language (this topic uses Node.js as an example). Then, set a project name, select a deployment region, and enter your Alibaba Cloud Container Registry image information.

  2. Run the following command to enter the project directory.

    cd start-fc3-custom-container-nodejs
  3. Edit the s.yaml file. For more information about the parameters in the YAML file, see YAML Specification.

    The following code provides an example.

    In this example, image refers to your Alibaba Cloud Container Registry image. Replace <your namespace>, <your image>, and <your tag> with your actual namespace, image repository name, and image tag. If you already entered the correct image information when you initialized the project in Step 1, you do not need to modify it here.

    edition: 3.0.0
    name: hello-world-app
    # access specifies the key configuration required by the current application:
    # For key configuration, see: https://www.serverless-devs.com/serverless-devs/command/config
    # For key usage order, see: https://www.serverless-devs.com/serverless-devs/tool#key-usage-order-and-specifications
    access: “default”
    
    vars: # Global variables
     region: “cn-hangzhou”
    
    resources:
     hello_world:
     # To perform operations only on the hello_world business module, append hello_world to the command line. For example:
     # To build only hello_world: s hello_world build
     # If you run s build directly without specifying hello_world, the tool will build all business modules at the same level as hello_world in the current YAML file (if there are other sibling modules, such as the commented next_function below) in a certain order
     component: fc3 # Component name
     actions: # Custom execution logic
     pre-deploy: # Run before deploy
     - component: fc3 build --dockerfile ./code/Dockerfile # Component to run, in the format “component: component_name command parameters”
     props:
     region: ${vars.region} # For variable usage, see: https://docs.serverless-devs.com/serverless-devs/yaml#%E5%8F%98%E9%87%8F%E8%B5%8B%E5%80%BC
     functionName: “start-nodejs-ufrz”
     runtime: “custom-container”
     description: 'hello world by serverless devs'
     timeout: 30
     memorySize: 512
     cpu: 0.5
     diskSize: 512
     code: ./code
     customContainerConfig:
     image: 'registry.${vars.region}.aliyuncs.com/<your namespace>/<your image>:<your tag>' # Your ACR image. Replace <your namespace>, <your image>, and <your tag> with the actual namespace name, image repository name, and image tag.
     # triggers:
     # - triggerName: httpTrigger # Trigger name
     # triggerType: http # Trigger type
     # description: 'xxxx'
     # qualifier: LATEST # Service version to trigger
     # triggerConfig:
     # authType: anonymous # Authentication type. Valid values: anonymous, function
     # disableURLInternet: false # Specifies whether to disable public network access URL
     # methods: # HTTP methods supported by the HTTP trigger. Valid values: GET, POST, PUT, DELETE, HEAD
     # - GET
     # - POST
  4. Run the following command to deploy the project.

    sudo s deploy

    The following output is an example:

      Steps for [deploy] of [hello-world-app]
    ====================
    
    DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
                BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
                environment-variable.
    
    Sending build context to Docker daemon   5.12kB
    Step 1/7 : FROM node:14-buster
    14-buster: Pulling from library/node
    2ff1d7c41c74: Already exists 
    b253aeafeaa7: Already exists 
    3d2201bd995c: Already exists 
    1de76e268b10: Already exists 
    d9a8df589451: Already exists 
    6f51ee005dea: Already exists 
    5f32ed3c3f27: Already exists 
    0c8cc2f24a4d: Already exists 
    0d27a8e86132: Already exists 
    Digest: sha256:a158d3b9b4e3fa813fa6c8c590b8f0a860e015ad4e59bbce5744d2f6fd8461aa
    Status: Downloaded newer image for node:14-buster
     ---> 1d12470fa662
    Step 2/7 : WORKDIR /usr/src/
     ---> Running in 70a8e2e4d1ea
    Removing intermediate container 70a8e2e4d1ea
     ---> 0d67b8fa2901
    Step 3/7 : COPY package*.json ./
     ---> 09eb15f8770a
    Step 4/7 : RUN npm install
     ---> Running in 8ae492be973b
    Step 5/7 : COPY . .
     ---> 7560c7b14431
    Step 6/7 : EXPOSE 9000
     ---> Running in 66b38e54ced0
    Removing intermediate container 66b38e54ced0
     ---> f73cce48d2ae
    Step 7/7 : ENTRYPOINT [ "node", "server.js" ]
     ---> Running in 2fb2f83fd6c0
    Removing intermediate container 2fb2f83fd6c0
     ---> fe51ae71448c
    Successfully built fe51ae71448c
    Successfully tagged registry.cn-hangzhou.aliyuncs.com/z****/z****:latest
    
    [2024-01-29 16:33:06][INFO][hello_world] get instanceName= and region=cn-hangzhou from registry.cn-hangzhou.aliyuncs.com/z****/z****
    [2024-01-29 16:33:06][INFO][hello_world] try to docker push registry.cn-hangzhou.aliyuncs.com/z****/z**** ...
    
    WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    Configure a credential helper to remove this warning. See
    https://docs.docker.com/engine/reference/commandline/login/#credentials-store
    
    Login Succeeded
    
    
    Using default tag: latest
    The push refers to repository [registry.cn-hangzhou.aliyuncs.com/z****/z****]
    85c1ec915b45: Pushed 
    37c36543a431: Pushed 
    e4afd7f70434: Pushed 
    0d5f5a015e5d: Layer already exists 
    3c777d951de2: Layer already exists 
    f8a91dd5fc84: Layer already exists 
    cb81227abde5: Layer already exists 
    e01a454893a9: Layer already exists 
    c45660adde37: Layer already exists 
    fe0fb3ab4a0f: Layer already exists 
    f1186e5061f2: Layer already exists 
    b2dba7477754: Layer already exists 
    latest: digest: sha256:6bf1ed4119d197a46c99082577632957056cb625f2ee0276d2af53f60d22837d size: 2841
    
    
    
      [hello_world] completed (688.45s)
    
      Result for [deploy] of [hello-world-app]
    ====================
    region:                cn-hangzhou
    cpu:                   0.5
    customContainerConfig: 
      image:            registry.cn-hangzhou.aliyuncs.com/z****/z****
      resolvedImageUri: registry.cn-hangzhou.aliyuncs.com/z****/z****@sha256:6bf1ed4119d197a46c99082577632957056cb625f2ee0276d2af53f60d22837d
    description:           hello world by serverless devs
    diskSize:              512
    functionName:          start-nodejs-ufrz
    handler:               handler
    instanceConcurrency:   1
    internetAccess:        true
    lastUpdateStatus:      Successful
    memorySize:            512
    role:                  
    runtime:               custom-container
    state:                 Active
    timeout:               30
    
    A complete log of this run can be found in: /root/.s/logs/0129162246
  5. Run the following command to debug the function.

    sudo s invoke -e "{\"key\":\"val\"}"

    The following output is an example:

     Steps for [invoke] of [hello-world-app]
    ====================
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: 1-65b764db-15eb737f-0c67ab5cd968
    FC Invoke Start RequestId: 1-65b764db-15eb737f-0c67ab5cd968
    hello world!
    
    FC Invoke End RequestId: 1-65b764db-15eb737f-0c67ab5cd968
    
    Duration: 42.27 ms, Billed Duration: 43 ms, Memory Size: 512 MB, Max Memory Used: 47.77 MB
    ========= FC invoke Logs end =========
    
    Invoke instanceId: c-65b764db-15fa2aa8-bc50f7839399
    Code Checksum: undefined
    Qualifier: LATEST
    RequestId: 1-65b764db-15eb737f-0c67ab5cd968
    
    Invoke Result:
    OK
      [hello_world] completed (4.96s)
    
    A complete log of this run can be found in: /root/.s/logs/0129164202