You can run commands by using on-premises development tools to create a WAR or JAR package for an application. Then, you can create an image based on the WAR or JAR package and upload the image to an Alibaba Cloud image repository to deploy the application. This topic describes how to create Enterprise Distributed Application Service (EDAS) application images by writing Dockerfiles and how to upload the images to an Alibaba Cloud image repository.
Prerequisites
You have read Appendix: Environment variables during runtime and the instructions described in this topic.
Usage notes
You can visit GitHub to query the Dockerfiles and images that are used in this topic.
Specifications and limits
Before you use Dockerfiles to create an EDAS application image, make sure that the following specifications are met and the following limits are observed:
Service information
The service information contains the information such as the EDAS domain name and the port to connect during runtime.
Table 4. Resources
Resource type
Resource name
Description
ConfigMap
edas-envs
The EDAS service information.
Table 5. Environment variables
Environment variable key
Type
Description
EDAS_ADDRESS_SERVER_DOMAIN
String
The service domain name or IP address of the configuration center.
EDAS_ADDRESS_SERVER_PORT
String
The service port of the configuration center.
EDAS_CONFIGSERVER_CLIENT_PORT
String
The service port of ConfigServer.
Required: environment variables during application runtime
EDAS provides environment variables when you deploy an application to ensure that the application can run as expected. We recommend that you do not overwrite the environment variable settings. For more information, see Appendix: Environment variables during runtime.
Create a standard Dockerfile
A Dockerfile is a configuration file in a text format. You can use a Dockerfile to create an image with efficiency.
You can use Dockerfiles to create images for High-speed Service Framework (HSF), Spring Cloud, or Dubbo applications based on your business requirements. The following examples describe how to create Dockerfiles for applications that use different frameworks.
An EDAS standard Dockerfile describes all the instructions for creating application runtime environments in EDAS. The instructions help you understand how to download, install, and start components, such as OpenJDK, Tomcat, and WAR and JAR packages. You can modify the Dockerfile for different purposes, such as replacing the OpenJDK version, modifying the Tomcat configuration, and changing the runtime environment. For more information about OpenJDK, see Custom image: Use the latest OpenJDK.
For more information about Dockerfiles, see the following sections:
Sample Dockerfile for an HSF application
# Using the centos7 + openjdk8 + ali tomcat7 + pandora 3.5.9 for the base
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"
# Default put your application package into /home/admin/app/
ENV APP_HOME /home/admin/app/
#####----> First case: deploy a fat-jar file
ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/HSF_PROVIDER.jar
#####----> Second case: deploy a war file, simply change the file name you wanted.
#ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/HSF_PROVIDER.war
#####----> Third case: deploy a local storage file.
#ARG APP_LOCATION=/Users/yanliang.lyl/workspace/java/demo/HSF_PROVIDER.war
# Then download the package into /home/admin/app/
ADD ${APP_LOCATION} ${APP_HOME}/
# Default working dir is set to /home/admin
# WORKDIR /home/admin
# Entry point set to /home/admin/bin/start.sh,
# which including inside basic image (apaas/edas-centos-openjdk8-alitomcat8)
# CMD ["/home/admin/bin/start.sh"]
Sample Dockerfile for a Spring Cloud or Dubbo application
# Using centos7 + openjdk8 + tomcat8 for the base
FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas:latest
# Default put your application package into /home/admin/app/
ENV APP_HOME /home/admin/app/
##### SIMPLE REPLACE YOUR PACKAGE FILE
#####----> First case: deploy a fat-jar file
ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/DUBBO_PROVIDER.jar
#####----> Second case: deploy a war file, simply change the file name you wanted.
#ARG APP_LOCATION=https://edas-hz.oss-cn-hangzhou.aliyuncs.com/prod/demo/DUBBO_PROVIDER.war
#####----> Third case: deploy a local storage file.
#ARG APP_LOCATION=/Users/yanliang.lyl/workspace/java/demo/SPRINT_CLOUD_PROVIDER.war
# Then download the package into /home/admin/app/
ADD ${APP_LOCATION} ${APP_HOME}/
Description of EDAS base images
You can use one of the following base images based on the runtime environment of your application.
Image name | OS version | Java version | Tomcat version | Pandora version | Description |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas | CentOS 7 | OpenJDK 1.8 | 8.5.78 | N/A | This image is the same as apaas/edas-centos-openjdk8-tomcat8. Latest version number: latest. |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-tomcat8 | CentOS 7 | OpenJDK 1.8 | 8.5.78 | N/A | We recommend that you use this image for common Spring Cloud or Dubbo applications. Latest version number: latest. |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-tomcat7 | CentOS 7 | OpenJDK 1.8 | 7.0.93 | N/A | We recommend that you use this image for common Spring Cloud or Dubbo applications running on Tomcat 7.x. Latest version number: latest. |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-alitomcat8 | CentOS 7 | OpenJDK 1.8 | 8.5.37 | 3.5.9 | We recommend that you use this image for HSF applications running on Tomcat 8.x. Latest version number: latest. |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-alitomcat7 | CentOS 7 | OpenJDK 1.8 | 7.0.92 | 3.5.9 | We recommend that you use this image for HSF applications running on Tomcat 7.x. Latest version number: latest. |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-alitomcat8-v4 | CentOS 7 | OpenJDK 1.8 | 8.5.37 | 4.0.2 | We recommend that you use this image for HSF 4.0 applications running on Tomcat 8.x. Latest version number: latest. |
apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas-centos-openjdk8-alitomcat7-v4 | CentOS 7 | OpenJDK 1.8 | 7.0.92 | 4.0.2 | We recommend that you use this image for HSF 4.0 applications running on Tomcat 7.x. Latest version number: latest. |
For more images, visit the official image repository aPaaS Docker Hub. If you need additional base images, join the DingTalk group (ID: 31723701) to obtain technical support. If you have questions about the base images, refer to the Dockerfiles of the base images in GitHub.
Custom image: Use the latest OpenJDK
You can specify custom settings in the created standard Dockerfile based on your business requirements.
Upgrade OpenJDK: You can download and install the latest OpenJDK in the Dockerfile. The following example shows how to download and install OpenJDK 9:
# Uninstall OpenJDK of an earlier version, and download and install OpenJDK 9.
RUN yum erase -y java; yum -y install java-1.9.0-openjdk-devel
Custom image: Upgrade the EDAS Container version for HSF applications
For the HSF applications that are deployed in Container Service for Kubernetes (ACK) clusters, you can upgrade the EDAS Container version to use the new features of the middleware or to fix the existing issues that may occur in an earlier version. To upgrade the EDAS Container version, perform the following steps:
Log on to the EDAS console.
In the left-side navigation pane, choose .
On the Applications page, click Create Application. In the Application Runtime Environment section of the Basic Information step, configure the Pandora Version and Ali-Tomcat Version parameters.
Replace the version number in the Dockerfile, such as 3.5.4.
# Specify the version of Pandora. ENV UPGRADED_CONTAINER_VERSION 3.5.4 RUN /home/admin/bin/upgradecontainer.sh
Create and publish an application image again.
Custom image: Modify JVM startup parameters in the image
The JAVA_OPTS environment variable is used to pass the Java virtual machine (JVM) parameters that are based on the base images. The following example shows how to modify the JVM startup parameters:
FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas:latest
# Configure the JVM parameter ENV
JAVA_OPTS="\
-Xmx3550m \
-Xms3550m \
-Xmn2g \
-Xss128k"
Custom image: Modify the configurations of a Spring Boot application
For the FatJar applications developed based on the EDAS base images, you can modify the Tomcat startup configurations, such as the context path, the startup port, and parameters. These parameters are passed based on the APP_ARGS environment variable. The following example shows how to modify the startup configurations:
FROM apaas-registry.cn-hangzhou.cr.aliyuncs.com/apaas/edas:latest
# The default configurations in the base image:
# - The context path (/) is used.
# - The encoded uniform resource identifier (URI) in ISO-8859-1 is used.
# - The application starts on port 8080.
# - The maximum number of the thread pools used by Tomcat is 400.
# You can also rewrite the environment variable APP_ARGS to modify the default configurations. Example:
ENV APP_ARGS="--server.context-path=/ \
--server.tomcat.uri-encoding=ISO-8859-1 \
--server.port=8080 \
--server.tomcat.max-threads=400"
Build an on-premises image
Access the directory where the Dockerfile is located by using an on-premises command line tool. Run one of the following docker build commands to build an image:
docker build -t [Label name, preferably application name]:[Version]. docker build -t [Label name, preferably application name]:[Version] -f /path/to/custom_dockerfile_name. # This command is applicable if the Dockerfile you created is located in another location or the name is not Dockerfile.
Example:
docker build -t hsf-provider:1.0.0 .
Then, run the
docker images | grep <Image label name>
command to view the packaged on-premises image.
Upload images to an image repository
You can upload the application images that are created and built on your on-premises computer to an Alibaba Cloud container image repository.
To upload images to a repository, perform the following steps: Log on to the Container Registry console. On the Instances page, switch to the region of the application created in EDAS or the region where you want to create an application. Select an instance as required. In the left-side navigation pane, click Repositories. View the image repository list and select an existing image repository or create an image repository to store your packaged application image. We recommend that you use the application name as the repository name for easy identification.
To upload an on-premises image to the image repository, run the commands that are used to push images to Container Registry. You can view these commands on the Details page of the specified image repository.
docker login --username=[Current logon username] registry.[region_id].aliyuncs.com # Enter the fixed or temporary password that is used as the access credential for the default instance in Container Registry. The password is not the one for your Alibaba Cloud account. docker tag [ID of the on-premises application image] registry.[region_id].aliyuncs.com/[Namespace name]/[Repository name]:[Image version]
docker push registry.[region_id].aliyuncs.com/[Namespace name]/[Repository name]:[Image 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.
Appendix: Environment variables during runtime
If you create a custom image by using a Dockerfile, specific environment variables are automatically used by EDAS during runtime. The following table describes these environment variables.
Environment variable key | Type | Description |
POD_IP | String | The IP address of the pod. |
EDAS_APP_ID | String | The ID of the EDAS application. |
EDAS_PROJECT_NAME | String | This parameter is the same as EDAS_APP_ID. This parameter is used for trace parsing. |
EDAS_JM_CONTAINER_ID | String | This parameter is the same as EDAS_ECC_ID. This parameter is used for trace parsing. |
EDAS_CATALINA_OPTS | String | The CATALINA_OPTS parameter that is required during middleware runtime. |
CATALINA_OPTS | String | This parameter is the same as EDAS_CATALINA_OPTS. This parameter is used as a default startup parameter of Tomcat. |
CATALINA_HOME | String | The Tomcat path. |
PANDORA_LOCATION | String | The Pandora path, which can be viewed in HSF applications. |
We recommend that you do not use the /home/admin/.spas_key/default file. This file is overwritten when the pod runs.