tencent cloud

Serverless Cloud Function

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Related Concepts
How It Works
Strengths
Scenarios
Related Products
Purchase Guide
Billing Overview
Billing Mode
Billable Items and Billing Modes
Function Computing Power Support
Free Tier
SCF Pricing
Billing Example
Payment Overdue
Getting Started
Creating Event Function in Console
User Guide
Quota Management
Managing Functions
Web Function Management
Log Management
Concurrence Management
Trigger Management
Function URL
A Custom Domain Name
Version Management
Alias Management
Permission Management
Running Instance Management
Plugin Management
Managing Monitors and Alarms
Network Configuration
Layer Management
Execution Configuration
Extended Storage Management
DNS Caching Configuration
Resource Managed Mode Management
Near-Offline Resource Hosting Model
Workflow
Triggers
Trigger Overview
Trigger Event Message Structure Summary
API Gateway Trigger
COS Trigger
CLS Trigger
Timer Trigger
CKafka Trigger
Apache Kafka Trigger
MQTT Trigger
Trigger Configuration Description
MPS Trigger
CLB Trigger Description
TencentCloud API Trigger
Development Guide
Basic Concepts
Testing a Function
Environment Variables
Dependency Installation
Using Container Image
Error Types and Retry Policies
Dead Letter Queue
Connecting SCF to Database
Automated Deployment
Cloud Function Status Code
Common Errors and Solutions
Developer Tools
Serverless Web IDE
Calling SDK Across Functions
Third-Party Tools
Code Development
Python
Node.js
Golang
PHP
Java
Custom Runtime
Deploying Image as Function
Web Framework Development
Deploying Framework on Command Line
Quickly Deploying Egg Framework
Quickly Deploying Express Framework
Quickly Deploying Flask Framework
Quickly Deploying Koa Framework
Quickly Deploying Laravel Framework
Quickly Deploying Nest.js Framework
Quickly Deploying Next.js Framework
Quickly Deploying Nuxt.js Framework
Quickly Deploying Django Framework
Use Cases
Overview
Solutions with Tencent Cloud Services
Business Development
TRTC Practices
COS Practices
CKafka Practice
CLS
CLB Practice
MPS
CDN
CDWPG
VOD
SMS
ES
Scheduled Task
Video Processing
Success Stories
Tencent Online Education
Online Video Industry
Tencent Online Education
Best Practice of Tencent IEG Going Global
API Documentation
History
Introduction
API Category
Making API Requests
Other APIs
Namespace APIs
Layer Management APIs
Async Event Management APIs
Trigger APIs
Function APIs
Function and Layer Status Description
Data Types
Error Codes
SDK Documentation
FAQs
General
Web Function
Billing FAQs
Network FAQs
Log FAQs
SCF utility class
Event Handling FAQs
API Gateway Trigger FAQs
Related Agreement
Service Level Agreement
Contact Us
Glossary

Using Container Image

PDF
フォーカスモード
フォントサイズ
最終更新日: 2024-12-02 19:46:29

Overview

The SCF container image feature has been launched, so you can use images for development. This document describes how to install an image and use it for development.

Prerequisites

Docker has been installed in the development environment.

Directions

Getting image

The SCF image is based on CentOS 7.7.1908 and available as a public image in TKE. You can search for scf-repo on the public image page to view the image information.
1. Run the following command to pull the image:
# Pull the SCF source image
docker pull ccr.ccs.tencentyun.com/scf-repo/scf-runtimes-image:latest
Note:
If the command prompts a permission error and cannot be executed normally, add sudo before the command and try again.
2. You can view the runtime contained in the current image in the /scf/lang/ directory. As the SCF source image contains all runtimes, it is relatively large. Please refer to the following table and choose a runtime image according to your needs.
Runtime
Address
SCF
ccr.ccs.tencentyun.com/scf-repo/scf-runtimes-image:latest
Go 1.8
ccr.ccs.tencentyun.com/scf-repo/runtime-go1:latest
Python 2.7
ccr.ccs.tencentyun.com/scf-repo/runtime-python2:latest
Python 3.6
ccr.ccs.tencentyun.com/scf-repo/runtime-python3:latest
PHP 5.6
ccr.ccs.tencentyun.com/scf-repo/runtime-php5:latest
PHP 7.2
ccr.ccs.tencentyun.com/scf-repo/runtime-php7:latest
Java 8
ccr.ccs.tencentyun.com/scf-repo/runtime-java8:latest
Node.js 6.10
ccr.ccs.tencentyun.com/scf-repo/runtime-node6:latest
Node.js 8.9
ccr.ccs.tencentyun.com/scf-repo/runtime-node8:latest
Node.js 10.15
ccr.ccs.tencentyun.com/scf-repo/runtime-node10:latest
Node.js 12.16
ccr.ccs.tencentyun.com/scf-repo/runtime-node12:latest
3. This document uses the scf:python3 tag as an example. Run the following command to retag the image:
docker pull ccr.ccs.tencentyun.com/scf-repo/runtime-python3:latest
# Run this command to find the IMAGE ID and copy it
docker images
# docker tag IMAGE_ID REPOSITORY:TAG
docker tag 0729ecc15d37 scf:python3
The execution result is as shown below:
image-20201204112659373


Note:
If you don't want to tag the image, you need to replace scf:python3 in the sample with ccr.ccs.tencentyun.com/scf-repo/runtime-python3:latest.

Using image for dependency installation

This document uses the NodeJieba dependency in the Node.js 12 environment as an example to describe how to install dependencies with an image.

Getting Node.js 12 image

Run the following command to pull the image:
docker pull ccr.ccs.tencentyun.com/scf-repo/runtime-node12:latest
# Run this command to find the IMAGE ID and copy it
docker images
docker tag d64a665357b6 scf:node12

Starting container and mounting directory

Run the following command to start the container and mount the local directory to a directory in the container (if the directory does not exist, it will be created automatically). This document uses mounting the /path/to/your_project directory to the /tmp/your_project directory in the container as an example.
docker run -it -v /path/to/your_project:/tmp/your_project scf:node12 /bin/bash

Installing dependencies in container

1. After starting the container, run the cd command to enter the directory in the container. Then, run the npm command to install NodeJieba in this directory as shown below:
cd /tmp/your_project
npm install nodejieba --save
2. The dependency will be installed in the local /path/to/your_project directory. Run the exit command to exit the container as shown below:
# Exit the container
exit
Following the above steps, you can install dependencies through the container image and then redeploy the code to SCF. For the Node.js language, online dependency installation is also supported, so that dependencies will be automatically installed upon upload.

Using image for development

This document uses Python 3.6 as an example to describe how to use a container for development and testing.

Getting Python 3.6 image

Run the following command to pull the image:
docker pull ccr.ccs.tencentyun.com/scf-repo/runtime-python3:latest
# Run this command to find the IMAGE ID and copy it
docker images
docker tag d64a665357b6 scf:python3

Starting container and mounting directory

1. Run the following command to start the container and mount the local project directory to a directory in the container (if the directory does not exist, it will be created automatically):
docker run -it -v /path/to/your_project:/tmp/your_project scf:node12 /bin/bash
2. Run the docker exec command to enter the container for development as shown below:
docker ps
# Get the CONTAINER ID
docker exec -it CONTAINER_ID /bin/bash

Saving image

Run the following command to submit changes to the local image for subsequent use:
# Get the container ID
docker ps
# Save the image locally
# docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
docker commit db47b8e66e64 scf:myimage


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック