Build an OSS Connector for AI/ML Docker image

更新时间:
复制 MD 格式

This topic describes how to use Docker to build an image that contains an OSS Connector for AI/ML environment.

Prerequisites

  • Docker is installed.

  • An access credential configuration file and an OSS connector configuration file are created. For more information, see Configure OSS Connector for AI/ML.

Example

The following example describes how to build a Docker image that contains OSS Connector for AI/ML Python3.12.

  1. Create a text file named Dockerfile in Linux to build a Docker image.

    touch Dockerfile
  2. Add the following configurations to the Dockerfile file and save the file.

    # Specify the base image. You can replace the base image with a user image. 
    FROM python:3.12.4
    # Specify the working directory. 
    WORKDIR /app
    # Copy the files in the current directory to the /app directory in the container. In most cases, the COPY command is used to copy the project file and the required configuration file. 
    COPY . /app
    # Install OSS Connector for AI/ML. 
    RUN pip install osstorchconnector
  3. Run the following command to build a Docker image.

    your_image_name in the command specifies the name of the image that you want to build. Specify the parameter based on your business requirements.

    docker build -t your_image_name .
  4. Run the following command to start the container and mount the access credential configuration file and OSS connector configuration file on the host:

    docker run -it --name new-container-name -v /root/.alibabacloud/credentials:/app/credentials -v /etc/oss-connector/config.json:/app/config.json your_image_name bash

    After the container starts, you have a containerized environment with the OSS Connector for AI/ML. It also contains the mounted OSS connector configuration file and access credential configuration file, as shown below.

    root@iZbp18kvqojqg0iy5uo8teZ:~# docker run -it --name new-container-name -v /root/.alibabacloud/credentials:/app/credentials -v /etc/oss-connector/config.json:/app/config.json your_image_name
    root@a70d7f0e6695:/app# ls
    Dockerfile  config.json  credentials
    root@a70d7f0e6695:/app#

References

When you use a containerized environment in which OSS Connector for AI/ML is installed for training tasks, you can perform the following operations: