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.
- 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
- Create a service and set permissions for it.
- In the Function Compute console, create a service. For more information, see Create a service.
- Assign the AliyunContainerRegistryReadOnlyAccess or AliyunContainerRegistryFullAccess permission policy to the service. For more information, see Configure service permissions.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.
- Create a function.In this example, an event function is created. HTTP functions use similar parameter settings.
- Log on to the Function Compute console.
- In the top navigation bar, select your region.
- In the left-side navigation pane, click Service/Function.
- Click Create Function. On the page that appears, select Event Function and click Next.
- In the Configure Function step, set the parameters and click Create.
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:
For more information about instance types, see Instance specifications and usage modes.
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,
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,
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 512 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 Concurrent requests in a single instance.
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.
- 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
- In template.yml, replace the value of the Image parameter with the address of your Alibaba Cloud Container Registry (ACR) image.
- 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-internetAfter 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.