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.
Docker has been installed in the development environment.
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.
# 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.
/scf/lang/
directory.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 |
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:Note:
If you don't want to tag the image, you need to replace
scf:python3
in the sample withccr.ccs.tencentyun.com/scf-repo/runtime-python3:latest
.
This document uses the NodeJieba dependency in the Node.js 12 environment as an example to describe how to install dependencies with an 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
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
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
/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.
This document uses Python 3.6 as an example to describe how to use a container for development and testing.
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
docker run -it -v /path/to/your_project:/tmp/your_project scf:node12 /bin/bash
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
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
Was this page helpful?