You can use commands in local development tools to package an application into a WAR or a JAR package for direct deployment. Alternatively, you can create an image based on a WAR or a JAR package, and then upload the image to the Alibaba Cloud image repository for deployment. This topic describes how to create the Dockfiles for images of applications with different frameworks and how to upload the images to the Alibaba Cloud image repository.

Prerequisites

Before creating an application image, read Regulations for creating an image. Follow the instructions and steps below to create an image for an Enterprise Distributed Application Service (EDAS) application.

Create a standard Dockerfile

A Dockerfile is a configuration file in text format. You can use the Dockerfile to quickly create an image.

You can use the Dockerfile to create images for High-speed Service Framework (HSF), Spring Cloud, or Dubbo applications. The following examples describe how to create Dockerfiles for applications with different frameworks.

An EDAS standard Dockerfile describes all instructions for creating application runtime environments in EDAS, including downloading, installing, and starting OpenJDK, Tomcat, and the WAR and the JAR packages. You can modify the Dockerfile to replace the OpenJDK version, modify the Tomcat configuration, and change the runtime environment. For more information, see Customize the Dockerfile.

The following examples show how to create Dockerfiles for images of applications with different frameworks. Note that the CATALINA_OPTS parameter needs to be included in the Dockerfile of a JAR package application. Otherwise, errors might occur in application service registration and configuration reading.

Dockerfile example of an HSF application (based on a WAR package)

FROM centos:7
MAINTAINER EDAS development team <edas-dev@list.alibaba-inc.com>

# Install the required software for packaging.
RUN yum install -y wget unzip telnet lsof net-tools bind-utils

# Prepare the JDK or the Tomcat system variables and paths.
ENV JAVA_HOME /usr/java/latest
ENV CATALINA_HOME /home/admin/taobao-tomcat
ENV PATH ${JAVA_HOME}/bin:${CATALINA_HOME}/bin:${PATH}

# Set the version of EDAS Container or Pandora.
ENV EDAS_CONTAINER_VERSION V3.5.4
LABEL pandora V3.5.4

# Download and install OpenJDK.
RUN yum -y install java-1.8.0-openjdk-devel

# Create a JAVA_HOME symbolic link.
RUN if [ ! -L "${JAVA_HOME}" ]; then mkdir -p 'dirname ${JAVA_HOME}' && ln -s 'readlink -f /usr/lib/jvm/java' ${JAVA_HOME}; fi

# Download and install Ali-Tomcat 7.0.92 to the directory: /home/admin/taobao-tomcat.
RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/edas-container/7.0.92/taobao-tomcat-production-7.0.92.tar.gz -O /tmp/taobao-tomcat.tar.gz && \
    mkdir -p ${CATALINA_HOME} && \
    tar -xvf /tmp/taobao-tomcat.tar.gz -C ${CATALINA_HOME} && \
    mv ${CATALINA_HOME}/taobao-tomcat-production-7.0.59.3/* ${CATALINA_HOME}/ && \
    rm -rf /tmp/taobao-tomcat.tar.gz ${CATALINA_HOME}/taobao-tomcat-production-7.0.59.3 && \
    chmod +x ${CATALINA_HOME}/bin/*sh

# Download and install EDAS Container or Pandora of the corresponding version based on environment variables.
RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/edas-plugins/edas.sar. ${EDAS_CONTAINER_VERSION}/taobao-hsf.tgz -O /tmp/taobao-hsf.tgz && \
    tar -xvf /tmp/taobao-hsf.tgz -C ${CATALINA_HOME}/deploy/ && \
    rm -rf /tmp/taobao-hsf.tgz

# Download and deploy the WAR package of the EDAS application demo.
RUN wget http://edas.oss-cn-hangzhou.aliyuncs.com/demo/hello-edas.war -O /tmp/ROOT.war && \
    unzip /tmp/ROOT.war -d ${CATALINA_HOME}/deploy/ROOT/ && \
    rm -rf /tmp/ROOT.war

# Set the Tomcat installation directory as the container startup directory. Start Tomcat in the run mode, and the catalina log is displayed in the standard command line.
WORKDIR ${CATALINA_HOME}
CMD ["catalina.sh", "run"]                

Dockerfile example of HSF applications (based on a JAR package)

FROM centos:7
MAINTAINER EDAS development team <edas-dev@list.alibaba-inc.com>

# Install the required software for packaging.
RUN yum install -y wget unzip telnet lsof net-tools bind-utils

# Prepare the JDK or the Tomcat system variables and paths.
ENV JAVA_HOME /usr/java/latest
ENV CATALINA_HOME /home/admin/taobao-tomcat
ENV PATH ${JAVA_HOME}/bin:${PATH}
ENV ADMIN_HOME /home/admin

# Set the version of EDAS Container or Pandora.
ENV EDAS_CONTAINER_VERSION V3.5.4
LABEL pandora V3.5.4

# Download and install OpenJDK.
RUN yum -y install java-1.8.0-openjdk-devel

# Create a JAVA_HOME symbolic link.
RUN if [ ! -L "${JAVA_HOME}" ]; then mkdir -p 'dirname ${JAVA_HOME}' && ln -s 'readlink -f /usr/lib/jvm/java' ${JAVA_HOME}; fi

# Download and install EDAS Container or Pandora of the corresponding version based on environment variables.
RUN mkdir -p ${CATALINA_HOME}/deploy/
RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/edas-plugins/edas.sar. ${EDAS_CONTAINER_VERSION}/taobao-hsf.tgz -O /tmp/taobao-hsf.tgz && \
    tar -xvf /tmp/taobao-hsf.tgz -C ${CATALINA_HOME}/deploy/ && \
    rm -rf /tmp/taobao-hsf.tgz

# Download and deploy the JAR package of the EDAS application demo.
RUN mkdir -p /home/admin/app/ && wget http://edas.oss-cn-hangzhou.aliyuncs.com/demoapp/fatjar-test-case-provider-0.0.1-SNAPSHOT.jar -O /home/admin/app/provider.jar

# Include the startup command in the startup script start.sh.
RUN echo '${JAVA_HOME}/bin/java -jar ${CATALINA_OPTS} -Djava.security.egd=file:/dev/./urandom -Dcatalina.logs=${CATALINA_HOME}/logs -Dpandora.location=${CATALINA_HOME}/deploy/taobao-hsf.sar "${ADMIN_HOME}/app/provider.jar" --server.context-path=/ --server.port=8080 --server.tomcat.uri-encoding=ISO-8859-1 --server.tomcat.max-threads=400' > ${ADMIN_HOME}/start.sh && chmod +x ${ADMIN_HOME}/start.sh

WORKDIR $CATALINA_HOME
CMD ["/bin/bash", "/home/admin/start.sh"]                

Dockerfile example of Spring Cloud or Dubbo applications (based on a WAR package)

FROM centos:7
MAINTAINER EDAS development team <edas-dev@list.alibaba-inc.com>

# Install the required software for packaging.
RUN yum install -y wget unzip telnet lsof net-tools bind-utils

# Prepare the JDK or Tomcat system variables.
ENV JAVA_HOME /usr/java/latest
ENV CATALINA_HOME /home/admin/apache-tomcat-7.0.91
ENV ADMIN_HOME /home/admin
ENV PATH ${JAVA_HOME}/bin:${CATALINA_HOME}/bin:${PATH}

RUN mkdir -p ${ADMIN_HOME}

# Download and install OpenJDK. 
RUN yum -y install java-1.8.0-openjdk-devel

# Create a JAVA_HOME symbolic link.
RUN if [ ! -L "${JAVA_HOME}" ]; then mkdir -p 'dirname ${JAVA_HOME}' && ln -s 'readlink -f /usr/lib/jvm/java' ${JAVA_HOME}; fi

# Download and install Tomcat.
RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/apache-tomcat-7.0.91.tar.gz -O /tmp/apache-tomcat-7.0.91.tar.gz && \
    tar -xvf /tmp/apache-tomcat-7.0.91.tar.gz -C ${ADMIN_HOME} && \
    rm /tmp/apache-tomcat-7.0.91.tar.gz && \
    chmod +x ${CATALINA_HOME}/bin/*sh

RUN mkdir -p ${CATALINA_HOME}/deploy/

# Add support for the Chinese language in containers.
ENV LANG="en_US.UTF-8"

# Enhance the web shell use experience.
ENV TERM=xterm

# Download and deploy the WAR package of the EDAS application demo.
RUN wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/demo/1.0/hello-edas.war -O /tmp/ROOT.war && \
    rm -rf ${CATALINA_HOME}/webapps/ROOT &&\
    unzip /tmp/ROOT.war -d ${CATALINA_HOME}/deploy/ROOT/ && \
    rm -rf /tmp/ROOT.war

# Set the Tomcat installation directory as the container startup directory. Start Tomcat in the run mode, and the catalina log is displayed in the standard command line.
WORKDIR ${ADMIN_HOME}
CMD ["catalina.sh", "run"]               

Dockerfile example of Spring Cloud or Dubbo applications (based on a JAR package)

FROM centos:7
MAINTAINER EDAS development team <edas-dev@list.alibaba-inc.com>

# Install the required software for packaging.
RUN yum install -y wget unzip telnet lsof net-tools bind-utils

# Prepare the JDK or Tomcat system variables.
ENV JAVA_HOME /usr/java/latest
ENV PATH ${JAVA_HOME}/bin:$PATH
ENV ADMIN_HOME /home/admin

# Download and install OpenJDK.
RUN yum -y install java-1.8.0-openjdk-devel

# Create a JAVA_HOME symbolic link.
RUN if [ ! -L "${JAVA_HOME}" ]; then mkdir -p 'dirname ${JAVA_HOME}' && ln -s 'readlink -f /usr/lib/jvm/java' ${JAVA_HOME}; fi

# Download and deploy the JAR package of the EDAS application demo.
RUN mkdir -p ${ADMIN_HOME}/app && \
         wget http://edas-hz.oss-cn-hangzhou.aliyuncs.com/demo/1.0/hello-edas-0.0.1-SNAPSHOT.jar -O ${ADMIN_HOME}/app/hello-edas-0.0.1-SNAPSHOT.jar

# Add support for the Chinese language in containers.
ENV LANG="en_US.UTF-8"

# Enhance the web shell use experience.
ENV TERM=xterm

# Include the startup command in the startup script start.sh.
RUN mkdir -p ${ADMIN_HOME}
RUN echo '${JAVA_HOME}/bin/java -jar ${CATALINA_OPTS} ${ADMIN_HOME}/app/hello-edas-0.0.1-SNAPSHOT.jar'> ${ADMIN_HOME}/start.sh && chmod +x ${ADMIN_HOME}/start.sh

WORKDIR ${ADMIN_HOME}

CMD ["/bin/bash", "/home/admin/start.sh"]                

Customize the Dockerfile

You can customize settings in the created standard Dockerfile as needed.

Upgrade OpenJDK: you can download and install a later version of OpenJDK in the Dockerfile. The following examples show how to download and install OpenJDK 9:

# Download and install OpenJDK 9.
RUN yum -y install java-1.9.0-openjdk-devel            

Upgrade the version of EDAS Container (for HSF applications only)

For HSF applications deployed in Container Service Kubernetes clusters, you can upgrade the EDAS Container version to use new middleware features or to fix the existing issues. The upgrade procedure is as follows:

  1. Log on to the EDAS console. In the left-side navigation pane, choose Application Management > Applications. In the upper-right corner of the Applications page, click Create Application. On the Application Information page, check Application Runtime Environment and the latest EDAS Container version (3.X.X).
  2. Choose an EDAS Container or Pandora version based on EDAS Container releases.
  3. Replace the version in the Dockerfile, such as 3.5.4.
    # Set the version of EDAS Container or Pandora.
    ENV EDAS_CONTAINER_VERSION V3.5.4                    
  4. Recreate and publish an application image.

Add the EDAS runtime environment to the Tomcat startup parameters.

EDAS provides the JVM environment variable EDAS_CATALINA_OPTS, which contains the minimum parameters required during runtime. Tomcat provides the customized JVM parameter configuration option JAVA_OPTS for setting parameters such as Xmx and Xms.

# Set the JVM parameters of the EDAS application.
ENV CATALINA_OPTS ${EDAS_CATALINA_OPTS}
# Set the JVM parameters.
ENV JAVA_OPTS="\
     -Xmx3550m \
     -Xms3550m \
     -Xmn2g \
     -Xss128k"       

Build a local image

Find the directory where the Dockerfile is located from the local command line. Run the docker build command to build an image:

docker build -t [Label name, preferably application name]:[version].
or
docker build -t [Label name, preferably application name]:[version] -f /path/to/custom_dockerfile_name.  # If the created Dockerfile is in another location or its name is not Dockerfile, use the latter command.            

Example:

docker build -t hsf-provider:1.0.0.            

Then use the docker images | grep<Image label name> command to view the packed local images.

Upload the image to the image repository

Application images created and built locally can be uploaded to Container Registry provided by Alibaba Cloud. Log on to the and select the region where your application is located. In the repository list, select an existing repository or create a new one to store your images. If you create a new repository, name it after your application for easy identification.

To upload the local image to the repository, run the commands of pushing images to registry provided on the Basic Information tab of the specified repository.

docker login --username=[current account name] registry.[region_i d].aliyuncs.com ... # Instead of entering your Alibaba Cloud account password, enter the fixed or temporary password that is used as the access credential for the default instance on Container Registry.
docker tag [ID of the local application image] registry.[region_i d].aliyuncs.com/[namespace name]/[repository name]:[image version]
docker push registry.[region_i d].aliyuncs.com/[namespace name]/[repository name]:[image version]            

Example:

docker login --username=tdy218@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            

Regulations for creating an image

Follow the specifications and restrictions below when using Dockerfile to create a custom image:

  • Tenant and encryption information

    The tenant and encryption information is used for user authentication and credential encryption of EDAS applications.

    • Resources
      Resource type Resource name Description
      Secret edas-certs An encryption dictionary that stores the EDAS tenant information.
    • Environment variables
      Environment variable key Resource name Description
      tenantId String The ID of an EDAS tenant.
      accessKey String The AccessKey ID for authentication.
      secretKey String The AccessKey secret for authentication.
    • Local files
      Path Type Description
      /home/admin/.spas_key/default File The authentication information of an EDAS tenant, which includes the preceding environment variable information.
  • Service information

    The service information includes the EDAS domain name and port to be connected during runtime.

    • Resources
      Resource type Resource name Description
      ConfigMap edas-envs The EDAS service information.
    • 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 port of Config Server
    • Environment variables during application runtime (required)

      The following environment variables are provided during the EDAS deployment to ensure the proper running of applications. For this reason, do not overwrite the current configuration.

      Environment variable key Type Description
      POD_IP String POD IP
      EDAS_APP_ID String The ID of the EDAS application.
      EDAS_ECC_ID String EDAS ECC ID
      EDAS_PROJECT_NAME String The same as EDAS_APP_ID, used for trace parsing.
      EDAS_JM_CONTAINER_ID String The same as EDAS_ECC_ID, used for trace parsing.
      EDAS_CATALINA_OPTS String The CATALINA_OPTS parameter required during the middleware runtime.
      CATALINA_OPTS String The same as EDAS_CATALINA_OPTS, which is a default startup parameter of Tomcat.