In on-premises container mode, the Alibaba Cloud Toolkit plug-in starts the container in an on-premises environment and runs your microservice application in the container. This topic describes how to configure the on-premises container mode.

Background information

The on-premises container mode provides the following advantages:

  • Non-Java microservice applications are supported.
  • On-premises microservice applications can run in an on-premises container that uses the same operating system as the container in the production environment.

    For example, if the on-premises environment uses a Windows operating system to develop applications but the production environment uses a Linux operating system to run applications, you can use the on-premises container mode to run a Linux container in the on-premises environment and run your microservice application in the Linux container.

The following figure shows the overall architecture in which the on-premises container mode is used.

8

Step 1: Configure the on-premises container mode

  1. Start IntelliJ IDEA.
  2. In the main menu bar, choose Run > Edit Configurations....
  3. In the Run/Debug Configurations dialog box, click the plus sign () in the upper-left corner. In the left-side navigation pane, expand Alibaba Microservice Container and click the name of your on-premises container. Then, configure the parameters related to the on-premises container in the right pane.
    9
    Parameter Description
    Name Enter a name of the on-premises container.
    Server Select a Docker daemon process from the Server drop-down list. The Alibaba Cloud Toolkit plug-in supports only the local Docker daemon process. The parameter value is fixed as Local Docker Server and cannot be changed.
    Application type Select an application type from the Application type drop-down list. If you select Image from the drop-down list, the Alibaba Cloud Toolkit plug-in uses the on-premises container image that you define to run your microservice container. If you select another application type from the drop-down list, the Alibaba Cloud Toolkit plug-in uses the default container to run your microservice application. Valid values:
    • Java: If your application is a Java application that is developed based on the Spring Cloud or Dubbo microservices framework and the package format is JAR, you can select this option.
    • Tomcat: If your application is a Java application that is developed based on the Spring Cloud or Dubbo microservices framework and the package format is WAR, you can select this option.
    • HSF-Container: If your application is a Java application that is developed based on the High-speed Service Framework (HSF) microservices framework and the package format is JAR or WAR, you can select this option.
    • Image: If you want to run a custom microservice container, you can select this option.
    Artifact Select the source of the microservice application package. This parameter is valid only if you do not select Image from the Application type drop-down list. Valid values:
    • Maven Build: Maven is used to build a project in the specified service module in an on-premises environment. Your application is run based on the package that is created in the project. If you select Maven Build, you must manually create a Maven project. For more information, see Maven project description.
    • Use File: A specified local file is used as the application package to run your application.
    Image ID or name Enter an ID or name of the custom container image. This parameter is valid only if you select Image from the Application type drop-down list.
    Entrypoint Enter an entry point of the container image. This parameter is valid only if you select Image from the Application type drop-down list. If you configure this parameter, the specified entry point overwrites the entry point of the custom container image.
    Command Enter a command for the container image. This parameter is valid only if you select Image from the Application type drop-down list. If you configure this parameter, the specified command overwrites the command for the custom container image.
    Bind ports Specify the mappings between host ports and container ports. The value is in the <Host port number>:<Container port number> format. Separate multiple port mappings with spaces. If you configure this parameter, you can use host ports to access the mapped container ports.
    Note By default, the Alibaba Cloud Toolkit plug-in exposes Spring Cloud service ports and debugging ports. Therefore, you do not need to configure this parameter. For more information, see Port mappings.
    Bind mounts Specify the mappings between host file directories and container file directories. The value is in the <Host file directory>:<Container file directory>. Separate multiple directory mappings with spaces. If you configure this parameter, a host and its mapped container can share the same file directories and separately read data from or write data to the shared file directories.
    Environment variables Enter the environment variables of the container in the <Key>=<Value> format. Separate multiple environment variables with semicolons (;).
    Note By default, the Alibaba Cloud Toolkit plug-in injects microservice-related parameters into the container. For more information, see Microservice environment variables.
  4. After the configuration is complete, click OK.

Step 2: Run the container

Run the container. If you run the container for the first time, the Alibaba Cloud Toolkit plug-in automatically pulls the default container image and related tools required by the underlying layer. This process is time-consuming. The following figure shows the startup log after the container is initialized.

10

(Optional) Step 3: Debug Java applications

The Alibaba Cloud Toolkit plug-in uses the JAVA_TOOL_OPTIONS parameter to enable Java application debugging and exposes the debugging port to the host. By default, port 5005 is used for debugging. If the port is occupied, the next consecutive port is used.

You can use related tools to connect to the debugging port. You can also use the debugger attaching feature that is provided by IntelliJ IDEA to debug Java applications.11

Port mappings

The Alibaba Cloud Toolkit plug-in maps the debugging ports and Spring Cloud service ports of Java applications to host ports.

  • Debugging ports: By default, port 5005 is used to debug Java applications. If the port is occupied, the next consecutive port is used. The Alibaba Cloud Toolkit plug-in uses the JAVA_TOOL_OPTIONS parameter to specify debugging information. If you do not use an image to start the container, the default container image uses the debugging information to run your microservice application. If you use a custom image to start the container, you must specify the AVA_TOOL_OPTIONS parameter in your startup script to start your microservice application.
  • Spring Cloud service ports: By default, port 8080 is used. If the port is occupied, the next consecutive port is used. The Spring Cloud service ports can be overwritten by the on-premises Spring Cloud service ports in the configurations for the interconnection between on-premises and cloud applications.

Microservice environment variables

When the Alibaba Cloud Toolkit plug-in starts, the plug-in ingests the following environment variables into the on-premises microservice container. If you do not use an image to start the container, the startup script of the default container image automatically identifies the following environment variables and starts the container. If you use a custom image to start the container, you can use these environment variables based on your business requirements.

Environment variable name Environment variable value
PRODUCT Specifies the cloud product type of the current runtime environment. You can set this environment variable to EDAS, SAE, or MSE.
JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=<Debugging port number>. By default, port 5005 is used for debugging. If the port is occupied, the next consecutive port is used.
ADDRESS_SERVER_HOST Specifies the host address of the Address Server.
ADDRESS_SERVER_PORT Specifies the port number of the Address Server.
ACCESS_KEY Specifies the AccessKey ID used in the namespace.
SECRET_KEY Specifies the AccessKey secret used in the namespace.
TENANT_ID Specifies the ID of the namespace.
SUB_ONLY This parameter is set to true if subscribeOnly is set to true in the configurations for the interconnection between on-premises and cloud applications.
PROJECT_NAME Specifies the ID of the application to which on-premises microservices belong.
REMOTE_IP Specifies the internal IP address of the remote proxy. By default, the IP address of eth0 is used.

Maven project description

If you select Maven Build for Artifact, you must add a Maven project to the container configuration.

  1. In the on-premises container configuration, click the plus sign (+) in the Before launch section. Then, select Run Maven Goal in the feature list that appears.
  2. In the Select Maven Goal dialog box, specify the module and command that correspond to the Maven project.
    12

    If your Maven project contains multiple modules, we recommend that you perform the following operations in sequence:

    1. For your Maven project, enter clean install in the Command line field.
    2. For your projects in the modules, enter clean package in the Command line field. If you enter clean package in the Command line field for a module, the Alibaba Cloud Toolkit plug-in uses the package that is created in the module project to run the container.