tencent cloud

Feedback

Using Container Image

Last updated: 2021-01-21 14:26:17

    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
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support