Alibaba Cloud Function Custom Container Timeout - Macbook M1 Chip

Mofei Zhu

I was free for the weekend, Decided to migrate my Alibaba Cloud Function Compute for my blog from a custom-runtime environment to a custom container. But, After deployment, I found that I couldn't access it, and it returned a timeout error:

  "ErrorCode": "CAExited",
  "ErrorMessage": "The function either cannot be started or exited: ContainerStartDuration:120817427318. function cannot be started or exited already: rpc error: code = Code(106) desc = ContainerStartDuration:120000000000. check function health failed due to runtime process not started successfully or not listen on port 9000 "

The service is not up, but we can access the server locally with the command s local start --custom-domain auto. Based on this, I suspected that the Function Compute could not access the container. So, I pinned a few friends from Alibaba Cloud on DingTalk. After various investigations and tests, We finally found the reason: because I am using a MacBook with an M1 chip when building images locally, the docker will use the arm64 architecture by default, but Alibaba Cloud function computing currently only recognizes amd64 images, so it failed after deployment.

We found two solutions after various tricks:

Solution 1 - Manual build amd64 image solution:

This method solves the problem by manually building an amd64 image on M1 -> uploading it to the image service -> specifying not automatically pushing image push during deployment.

The specific process is as follows:

1. Build amd64 image

export DOCKER_DEFAULT_PLATFORM=linux/amd64
docker build -t <name>:<version> ./

2. Push amd64 image

docker push<name_space>/<name>:<version>

3. Deploy services through non-push mirroring

s deploy --skip-push

--skip-push official docs

Solution two:

It is a relatively easy solution. Change the From field of the image's Dockerfile to specify a practical amd64 image --platform=linux/amd64:

FROM --platform=linux/amd64 node:14.5.0-alpine3.11

Tested and found no problem with the Node.js-related image, but other images such as ASP and GO are not working with this. So if you build with this scheme, please run docker inspect <image> to confirm whether Architecture is amd64.