Run your own Docker image as a function, from a Dockerfile that points at the image. Use Custom
Container Image when your application has its own framework or runtime that the built-in templates
do not cover. A container function runs on CPU hardware and is billed as a CPU function. See
Billing.
Before you begin
Section titled “Before you begin”You need a public Docker image that is built for linux/amd64 and runs as a non-root user. A
private image, such as one in E2E Container Registry, cannot be used. By default the container must
listen on port 8080.
If your container listens on a different port, add an environment variable with this name, and set its value to the port number:
__PORT__Functions reserves the name PORT, so choose another.
Write the Dockerfile
Section titled “Write the Dockerfile”With Custom Container Image, the editor has two tabs. The Dockerfile tab holds the file the
platform builds. The DOCS.md tab holds the platform’s guidelines for writing that Dockerfile.
The template’s Dockerfile sets the architecture and the non-root user. It reads:
# Set your desired public base image here in BASE_IMAGE# ARG BASE_IMAGE=<YOUR-PUBLIC-CONTAINER_IMAGE>ARG BASE_IMAGE=e2efaasplatform/react-sampleFROM --platform=linux/amd64 ${BASE_IMAGE}
# Do not modify the following configurations# These ensure the container runs securely as a non-root userUSER 1001
# You can add your custom instructions below this line [Optional]Of the template’s lines, change only the BASE_IMAGE line. Set it to the address of your public
image. Keep USER 1001 as it is: the template marks it “Do not modify”. Add your own
instructions below the last comment.
Create the function
Section titled “Create the function”To upload the files as a ZIP instead, include both Dockerfile and DOCS.md. See
Upload code as a ZIP.
- In Create Function, choose Custom Container Image.
- In the
Dockerfiletab, set the BASE_IMAGE argument to your image. - Fill in the function name and, under System Configuration, the memory and timeout, as in Create a function.
- (Optional) If your container listens on a port other than 8080, add the port environment variable under Function Configuration, set to the port number. See Before you begin.
- (Optional) To keep instances always running, turn on Enable Dedicated Replica. See Keep a function ready with dedicated replicas.
- Click Create.
The function builds and deploys, then reads Running once your container is up.
Check that the function is running
Section titled “Check that the function is running”When the function reads Running, its public HTTPS URL is ready. Call it to confirm your container answers. See Call a function.
If the function reads Failed, open its page and read the Build Logs tab. See Troubleshooting Functions.
You now have a function running your own container image. To compare it with the built-in runtimes, see Runtimes and hardware.