All Products
Search
Document Center

Platform For AI:Deploy model services using custom images

Last Updated:Jan 16, 2026

Build custom images when official EAS images don't meet your needs. Package your complete runtime environment for flexible, reliable model deployments.

Plan your image repository

EAS pulls images from a container registry when deploying services. We recommend using Alibaba Cloud Container Registry (ACR) to store images and pull them over your VPC network for optimal performance and security.

Important

Don't pull images from the public internet. Public pulls are slow and insecure.

ACR Personal Edition

  • Free but limited to a single region. Cross-region image pulls require a public address.

  • Use ACR Personal Edition for testing only. Ensure it's in the same region as your EAS service.

ACR Enterprise Edition

  • Provides enhanced security, performance, and global synchronization. EAS services pull images over the internal network within the same region or across regions.

  • Use ACR Enterprise Edition for production.

Self-built image repositories

  • Self-hosted registries like Harbor in Alibaba Cloud VPC are accessible only within the VPC. Configure your EAS service to use the same VPC as your registry.

Image repository authentication

Private registries that require authentication need your username and password during deployment.

In your JSON configuration, use the dockerAuth parameter with the Base64-encoded username:password string.

For example, encode abcd:abcde12345 by running echo -n "abcd:abcde12345" | base64 to get the dockerAuth value: YWJjZDphYmNkZTEy****.

{"dockerAuth": "YWJjZDphYmNkZTEy****"}
Note

EAS pulls images from ACR without authentication when the registry and service use the same Alibaba Cloud account and region. No username or password needed.

Quick start: Create and deploy a custom image

Build a production-grade Flask and Gunicorn web service image on an ECS instance, push it to ACR, and deploy it to EAS.

Step 1: Prepare the environment

Before you begin, ensure you have:

  • Virtual Private Cloud (VPC): Your EAS service, ECS instance, and ACR registry must use the same VPC for stable, secure image transfers.

  • Container Registry (ACR): An ACR Enterprise Edition instance with a namespace and image repository. See Use an Enterprise Edition instance to push and pull images.

  • Development environment: An ECS instance with this configuration:

    Note

    You can also use a local machine or DSW environment.

    • Local development: Install Docker to build images locally.

    • DSW development: In the Actions column, click Create Image to build and save the image to ACR. During deployment, select Custom Image from the dropdown. See Create a DSW instance image.

Step 2: Prepare application files

Create a project folder named my-app with these three files:

  1. requirements.txt (Application dependencies)

    flask
    gunicorn
  2. app.py (Web application code)

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/hello/model')
    def hello_world():
        # Integrate your model inference or other business logic here.
        return 'Hello World from Gunicorn!'
    
    # Note: app.run() is not needed. Gunicorn will start the application.
  1. Dockerfile (Image build instructions)

    # 1. Use an official lightweight Python image as the base
    FROM python:3.9-slim
    
    # 2. Set the working directory
    WORKDIR /app
    
    # 3. Copy the requirements file and install dependencies, leveraging Docker's cache to speed up subsequent builds
    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
    
    # 4. Copy the application code
    COPY app.py .
    
    # 5. Expose the service port
    EXPOSE 8000
    
    # 6. Define the default container start command (which you can override with the "Command" in the EAS console)
    CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]

Step 3: Build and push the image

  1. Navigate to your project folder (my-app).

  2. Log in to ACR. Replace placeholders with your information.

    # Example: docker login --username=your_user my-registry.cn-hangzhou.aliyuncs.com
    docker login --username=<username> <ACR_repository_domain_name>
  3. Build and tag the image.

    # Example: docker build -t my-registry.cn-hangzhou.aliyuncs.com/my-namespace/flask-app:v1 .
    docker build -t <ACR_repository_domain_name>/<namespace>/<image_repository_name>:<version_number> .
  4. Push the image to ACR.

    # Example: docker push registry.cn-hangzhou.aliyuncs.com/my-namespace/flask-app:v1
    docker push <ACR_repository_domain_name>/<namespace>/<image_repository_name>:<version_number>

Step 4: Deploy the service

  1. Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Elastic Algorithm Service (EAS).

  2. Click Deploy Service and select Custom Model Deployment > Custom Deployment.

  3. Configure the following key parameters:

    • Deployment Method: Select Image-based Deployment.

    • Image Configuration: Select Image Address and enter the full image address.

      This example uses ACR in the same Alibaba Cloud account, so no authentication is needed.
    • Command to Run: gunicorn -w 4 -b 0.0.0.0:8000 app:app

      Note: Commands in the EAS console override the CMD in your Dockerfile. Specify the command here for easier debugging.
    • Port Number 8000.

    • Deployment: Select a CPU resource like ecs.c6.large from Public Resources.

    • VPC: Select a VPC, vSwitch, and security group.

      Ensure your VPC is in the ACR access control list. Missing VPC configuration causes ImagePullBackOff errors.
  4. Click Deploy. Deployment succeeds when the service status changes to Running.

Step 5: Test the service

After deployment succeeds, obtain the endpoint and token and test the Flask service:

# Replace <endpoint> and <token> with the actual service endpoint and token.
curl <endpoint>/hello/model -H "Authorization: <token>"

Hello World from Gunicorn! response confirms the service is running.

For more information about service invocation, see Service invocation methods.

Core concepts and limitations

  • Network limitations: EAS services require a VPC to access internal network resources. To access public internet resources (install dependencies with pip, call external APIs, or pull images from public registries), configure a NAT Gateway for your VPC. See Allow an EAS service to access the public network or internal resources.

    Cost implication: NAT Gateway incurs additional charges.
  • Port limitations: EAS reserves ports 8080 and 9090. Your application must not use these ports, or deployment will fail with port conflicts.

  • Sidecar injection: EAS injects a proxy container as a sidecar to handle authentication, authorization, and monitoring. This lightweight proxy securely forwards requests to your service port.

  • API protocol support: Custom images support HTTP, WebSocket, and gRPC (HTTP/2) protocols.

Recommendations for production applications

  • Separate images and models: Package code in your image and store models in Object Storage Service (OSS) or File Storage NAS. Use the storage mount feature to mount models at deployment. This reduces image pull times during updates and scaling.

  • Pull images over the internal network: Configure a VPC for your service to pull images from ACR using a VPC address for optimal security and performance.

  • Register images as AI assets: For reusable custom images, use PAI AI Assets to manage them as standardized assets.

  • Configure a health check: Enable health checks so EAS can automatically restart unhealthy instances. For more information, see Health check.

  • Enable auto scaling: For variable workloads, enable horizontal automatic scaling to handle traffic changes efficiently.

FAQ

Q: Why does my service fail with an ImagePullBackOff error?

The ImagePullBackOff error means EAS cannot pull your container image. This typically indicates one of these issues:

  1. Network connectivity issues

    Your EAS service's VPC must have network access to the image registry.

  2. Authentication failure

    Private registries require authentication credentials (ACR instances in the same account don't require credentials).

    • Action: Verify the username and password in Image Configuration are correct with pull permissions.

  3. Image not found

    The image path or tag is incorrect, or the image doesn't exist in the registry.

    • Action: Verify the image address, namespace, and tag match what you pushed to the registry.

  4. Insufficient system disk space

    The node's local storage is full and cannot store the image.

For more information about other issues, see EAS FAQ.