All Products
Search
Document Center

Serverless App Engine:Example of image creation

Last Updated:Jul 15, 2025

Creating SAE application images is the same as creating regular images. If you are unfamiliar, refer to the examples provided in this topic.

  1. Ensure Docker is installed and running in your environment. Verify this by docker --version.

  2. Navigate to your project directory and create Dockerfile. Here are examples of Dockerfilefor different programming languages.

    Java

    For directory structure as:

    .
    ├── Dockerfile # Newly created Dockerfile
    ├── target
    │   ├── my-app.jar # JAR package generated when building the project
    ├── src # Building the image only involves the Dockerfile and jar package, not the source code or other configuration files.
    │   ├── ...
    ├── pom.xml

    The Dockerfile content is:

    # Specify the base image, using openjdk 8 as an example
    FROM openjdk:8-jdk-alpine
    
    # Copy the local jar package to the image
    COPY ./target/my-app.jar /
    
    # Set the startup command
    ENTRYPOINT ["java", "-jar", "/my-app.jar"]

    PHP

    For directory structure as:

    .
    ├── Dockerfile # Newly created Dockerfile
    ├── entrypoint.sh # Newly created container startup script
    ├── php
    │   ├── index.php
    │   └── phpinfo.php
    ├── nginx
    │   ├── nginx.conf
    │   ├── conf.d
    │   |   ├── default.conf
    │   ├── fastcgi_params
    │   ├── ...

    The Dockerfile content is:

    # Specify the base image, using PHP-FPM image as an example
    FROM php:8.2-fpm-alpine
    
    # Install Nginx
    RUN apk add --no-cache nginx
    
    # Copy Nginx configuration files to the container
    COPY nginx/ /etc/nginx/
    
    # Copy PHP files to the working directory
    COPY php/ /var/www/html/
    
    # Copy the local startup script to the image, which will be executed when the container starts
    COPY entrypoint.sh /entrypoint.sh
    RUN chmod +x /entrypoint.sh
    ENTRYPOINT ["/entrypoint.sh"]
    

    The content of the startup script entrypoint.sh is as follows:

    #!/bin/sh
    
    # Start PHP-FPM in the background
    php-fpm -D
    
    # Check if PHP-FPM started successfully
    if ! pgrep "php-fpm" >/dev/null
    then
        echo "PHP-FPM failed to start!"
        exit 1
    fi
    
    # Run Nginx in the foreground
    nginx -g "daemon off;"

    Python

    For directory structure as:

    .
    ├── Dockerfile # Newly created Dockerfile
    ├── entrypoint.sh # Newly created container startup script
    ├── my_app
    │   ├── requirements.txt
    │   ├── main.py
    │   ├── my_package
    │   |   ├── __init__.py
    │   |   ├── ...

    The Dockerfile content is:

    # Specify the base image, using Python 3.9 image as an example
    FROM python:3.9
    
    # Copy local Python code to the image
    RUN mkdir -p /my_app
    COPY my_app/ /my_app/
    
    # Install dependencies in the image according to requirements.txt
    RUN pip install -r /my_app/requirements.txt
    
    # Copy the local startup script to the image, which will be executed when the container starts
    COPY entrypoint.sh /entrypoint.sh
    RUN chmod +x /entrypoint.sh
    ENTRYPOINT ["/entrypoint.sh"]
    

    The content of the startup script entrypoint.sh is as follows:

    #!/bin/sh
    
    # This example starts the app in my_app/main.py using Gunicorn, where app is a Flask instance. Flask and Gunicorn are specified in requirements.txt.
    gunicorn -w 3 -b 0.0.0.0:8080 my_app.main:app

    Node.js

    For a frontend project deployed with Nginx, with the directory structure as:

    .
    |- Dockerfile # Newly created Dockerfile
    |- nginx-conf # Directory for Nginx configuration files
    |  |- nginx.conf
    |  |- conf.d
    |  |  |- default.conf
    |  |- ...
    |- package.json
    |- src
    |  |- ...
    |- dist # Directory for static resource files generated after project build
    |  |- index.html
    |  |- static
    |  |  |- ...

    The Dockerfile content is:

    # Specify the base image
    FROM nginx:1.22
    
    # Copy local static resource files to the specified path in the container environment
    COPY ./dist /usr/share/nginx/html/
    
    # Copy local Nginx configuration files to the specified path in the container environment
    COPY ./nginx-conf /etc/nginx/
    
    # Use the startup command from the base image, no additional settings needed
  3. Build the image: docker build -t <image name>:<image tag> . (for example, docker build -t my-app:1.0 .)

  4. Push the image to an image repository. If existing image repository does not meet your requirements, use Alibaba Cloud Container Registry ACR Personal Edition or ACR Enterprise Edition.

  5. Based on the type of image repository, choose from Deploy applications using images from ACR instances under the same account, Deploy applications using images from ACR instances under different accounts, or Deploy applications using images from non-ACR instances.