Create an application image

Updated at:

You can create a WAR or JAR package for an application by using on-premises development tools, then create a Docker image based on the package and upload it to an Alibaba Cloud image repository to deploy the application. EDAS provides pre-built base images for three application frameworks -- HSF (High-speed Service Framework), Spring Cloud, and Dubbo -- so you only need to write a minimal Dockerfile that copies your WAR or JAR package into the image.

Each base image bundles a specific combination of OS, JDK, and Tomcat. HSF base images also include the Pandora middleware container.

Prerequisites

Before you begin, make sure that you have:

  • A local Docker installation

  • A WAR or JAR application package ready to deploy

  • An Alibaba Cloud Container Registry instance with an image repository

For information about environment variables that EDAS injects at runtime, see Runtime environment variables.

Choose a base image

Select a base image based on your application framework and runtime requirements.

Base image Java Tomcat Pandora Use case
apaas/edas OpenJDK 1.8 8.5.78 N/A Spring Cloud or Dubbo (alias for edas-centos-openjdk8-tomcat8)
apaas/edas-centos-openjdk8-tomcat8 OpenJDK 1.8 8.5.78 N/A Spring Cloud or Dubbo on Tomcat 8.x
apaas/edas-centos-openjdk8-tomcat7 OpenJDK 1.8 7.0.93 N/A Spring Cloud or Dubbo on Tomcat 7.x
apaas/edas-centos-openjdk8-alitomcat8 OpenJDK 1.8 8.5.37 3.5.9 HSF on Ali-Tomcat 8.x
apaas/edas-centos-openjdk8-alitomcat7 OpenJDK 1.8 7.0.92 3.5.9 HSF on Ali-Tomcat 7.x
apaas/edas-centos-openjdk8-alitomcat8-v4 OpenJDK 1.8 8.5.37 4.0.2 HSF 4.0 on Ali-Tomcat 8.x
apaas/edas-centos-openjdk8-alitomcat7-v4 OpenJDK 1.8 7.0.92 4.0.2 HSF 4.0 on Ali-Tomcat 7.x
apaas/edas-centos7-openjdk17-tomcat9 OpenJDK 17 9.0.70 N/A OpenJDK 17 + Tomcat 9
apaas/edas-centos7-openjdk17-tomcat10 OpenJDK 17 10.1.41 N/A OpenJDK 17 + Tomcat 10

All images are hosted at apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/ and run on CentOS 7. The latest tag is latest.

For more images, visit aPaaS Docker Hub. For technical support, join DingTalk group ID 31723701. For the source Dockerfiles behind these base images, see the alibabacloud-edas-dockerfile-demo repository on GitHub.

Write a Dockerfile

A Dockerfile defines the instructions to assemble your application image. The EDAS base images already include the JDK, Tomcat, and startup scripts, so the Dockerfile only needs to copy your application package into the image.

HSF applications

HSF applications require an Ali-Tomcat base image with the Pandora middleware container.

# Base: CentOS 7 + OpenJDK 8 + Ali-Tomcat 7 + Pandora 3.5.9
FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-alitomcat7:latest
MAINTAINER Alibaba Cloud EDAS Team<edas-**@list.alibaba-inc.com>

ENV TZ="Asia/Shanghai"

# Application directory inside the container
ENV APP_HOME /home/admin/app/

##### Deploy a JAR file (default)
ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/HSF_PROVIDER.jar

##### Deploy a WAR file -- uncomment the line below and comment out the JAR line
#ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/HSF_PROVIDER.war

##### Deploy from local storage -- uncomment and set the path to your local file
#ARG APP_LOCATION=/path/to/your/HSF_PROVIDER.war

# Copy the application package into the container
ADD ${APP_LOCATION} ${APP_HOME}/

# The startup script and working directory are provided by the base image.
# Entry point: /home/admin/bin/start.sh
# Working directory: /home/admin

Spring Cloud or Dubbo applications

Spring Cloud and Dubbo applications use the standard EDAS base image (without Pandora).

# Base: CentOS 7 + OpenJDK 8 + Tomcat 8
FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas:latest

# Application directory inside the container
ENV APP_HOME /home/admin/app/

##### Deploy a JAR file (default)
ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/DUBBO_PROVIDER.jar

##### Deploy a WAR file -- uncomment the line below and comment out the JAR line
#ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/DUBBO_PROVIDER.war

##### Deploy from local storage -- uncomment and set the path to your local file
#ARG APP_LOCATION=/path/to/your/SPRING_CLOUD_PROVIDER.war

# Copy the application package into the container
ADD ${APP_LOCATION} ${APP_HOME}/

Customize the image

After creating a base Dockerfile, apply any of the following customizations.

Upgrade OpenJDK

Install a newer JDK version directly in the Dockerfile. EDAS supports up to OpenJDK 21 for custom images.

The following example replaces the pre-installed OpenJDK 8 with OpenJDK 9:

# Remove the pre-installed JDK and install OpenJDK 9
RUN yum erase -y java; yum -y install java-1.9.0-openjdk-devel

Upgrade the EDAS Container version (HSF only)

For HSF applications in ACK clusters, upgrade the Pandora and Ali-Tomcat versions to access new middleware features or fixes.

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, choose Application Management > Applications.

  3. On the Applications page, click Create Application. In the Application Runtime Environment section of the Basic Information step, find the available Pandora Version and Ali-Tomcat Version values.

  4. Set the target version in the Dockerfile. For example, to upgrade to Pandora 3.5.4:

        # Upgrade the Pandora version
        ENV UPGRADED_CONTAINER_VERSION 3.5.4
        RUN /home/admin/bin/upgradecontainer.sh
  5. Rebuild and push the image.

Set JVM startup parameters

Pass JVM parameters through the JAVA_OPTS environment variable:

FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas:latest

# Set JVM memory parameters
ENV JAVA_OPTS="\
     -Xmx3550m \
     -Xms3550m \
     -Xmn2g \
     -Xss128k"

Configure Spring Boot settings

For FatJar applications, modify Tomcat startup settings through the APP_ARGS environment variable. The base image uses the following defaults:

Parameter Default
Context path /
URI encoding ISO-8859-1
Port 8080
Max Tomcat threads 400

Override these defaults as needed:

FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas:latest

# Override Spring Boot defaults
ENV APP_ARGS="--server.context-path=/  \
              --server.tomcat.uri-encoding=ISO-8859-1 \
              --server.port=8080 \
              --server.tomcat.max-threads=400"

Build and push the image

Build the image

  1. Open a terminal and navigate to the directory that contains your Dockerfile.

  2. Run docker build to create the image: Example: If your Dockerfile has a non-default name or location, specify it with the -f flag:

        docker build -t <app-name>:<version> .
        docker build -t hsf-provider:1.0.0 .
        docker build -t hsf-provider:1.0.0 -f /path/to/custom_dockerfile .
  3. Verify that the image was created:

        docker images | grep hsf-provider

Push the image to Container Registry

After you build the image, push it to Alibaba Cloud Container Registry.

Set up a repository

  1. Log on to the Container Registry console.

  2. On the Instances page, switch to the region where your EDAS application runs (or where you plan to create one).

  3. Select an instance, then click Repositories in the left-side navigation pane.

  4. Select an existing repository or create one. Use the application name as the repository name for easy identification.

Push the image

Run the following commands. Replace the placeholders with your actual values.

Placeholder Description Example
<username> Container Registry login username td****@gmail.com
<region-id> Region of your Container Registry instance cn-hangzhou
<image-id> Local image ID from docker images 2b64f63601a7
<namespace> Container Registry namespace webapps
<repository> Repository name hsf-provider
<version> Image version tag 1.0.0
# Step 1: Log in to Container Registry
# Enter the fixed or temporary password for the default instance in Container Registry, not your Alibaba Cloud account password.
docker login --username=<username> registry.<region-id>.aliyuncs.com

# Step 2: Tag the image
docker tag <image-id> registry.<region-id>.aliyuncs.com/<namespace>/<repository>:<version>

# Step 3: Push the image
docker push registry.<region-id>.aliyuncs.com/<namespace>/<repository>:<version>

Example:

docker login --username=td****@gmail.com registry.cn-hangzhou.aliyuncs.com
docker tag 2b64f63601a7 registry.cn-hangzhou.aliyuncs.com/webapps/hsf-provider:1.0.0
docker push registry.cn-hangzhou.aliyuncs.com/webapps/hsf-provider:1.0.0

To accelerate the network of an Alibaba Cloud image repository, perform the following steps: Log on to the Container Registry console. In the left-side navigation pane, click Image Tool. Then, click Image Accelerator. On the Image Accelerator page, obtain the value of the Booster URL parameter.

Speed up image pulls with Image Accelerator

  1. Log on to the Container Registry console.

  2. In the left-side navigation pane, click Image Tool, then click Image Accelerator.

  3. On the Image Accelerator page, obtain the Booster URL.

Runtime environment variables

EDAS injects environment variables into each pod through a Kubernetes ConfigMap named edas-envs. Do not overwrite these values.

Service configuration variables

Environment variable Type Description
EDAS_ADDRESS_SERVER_DOMAIN String Domain name or IP address of the configuration center
EDAS_ADDRESS_SERVER_PORT String Port of the configuration center
EDAS_CONFIGSERVER_CLIENT_PORT String Port of ConfigServer

Application runtime variables

Environment variable Type Description
POD_IP String IP address of the pod
EDAS_APP_ID String EDAS application ID
EDAS_PROJECT_NAME String Same as EDAS_APP_ID; used for trace parsing
EDAS_JM_CONTAINER_ID String Same as EDAS_ECC_ID; used for trace parsing
EDAS_CATALINA_OPTS String CATALINA_OPTS parameters for middleware runtime
CATALINA_OPTS String Same as EDAS_CATALINA_OPTS; default Tomcat startup parameter
CATALINA_HOME String Tomcat installation path
PANDORA_LOCATION String Pandora installation path (HSF applications only)
Warning

Do not use the /home/admin/.spas_key/default file. EDAS overwrites this file when the pod starts.