Updated on 2023-12-07 GMT+08:00

Preparing the Application Runtime

After application analysis, you have gained the understanding of the OS and runtime required for running the application. Make the following preparations:

  • Installing Docker: During application containerization, build a container image. To do so, you have to prepare a PC and install Docker on it.
  • Obtaining the base image tag: Determine the base image based on the OS on which the application runs. In this example, the application runs on CentOS 7.1 and the base image can be obtained from an open-source image repository.
  • Obtaining the runtime: Obtain the runtime of the application and the MongoDB database with which the application interconnects.

Installing Docker

Docker is compatible with almost all operating systems. Select a Docker version that best suits your needs.

SWR uses Docker 1.11.2 or later to upload images.

You are advised to install Docker and build images as user root. Obtain the password of user root of the host where Docker is to be installed in advance.

  1. Log in as user root to the device on which Docker is about to be installed.
  2. Quickly install Docker on the device running Linux. You can also manually install Docker. For details, see Docker Engine installation.

    curl -fsSL get.docker.com -o get-docker.sh

    sh get-docker.sh

  3. Run the following command to query the Docker version:

    docker version
    Client:
    Version: 17.12.0-ce
    API Version:1.35
    ...

    Version indicates the version number.

Obtaining the Base Image Tag

Determine the base image based on the OS on which the application runs. In this example, the application runs on CentOS 7.1 and the base image can be obtained from an open-source image repository.

Search for the image tag based on the OS on which the application runs.

  1. Visit the Docker website.
  2. Search for CentOS. The image corresponding to CentOS 7.1 is centos7.1.1503. Use this image name when editing the Dockerfile.

    Figure 1 Obtaining the CentOS version

Obtaining the Runtime

In this example, the web application of the Tomcat type is used. This application requires the runtime of Tomcat 7.0, and Tomcat requires JDK 1.8. In addition, the application must interconnect with the MongoDB database in advance.

Download the environment required by the application.

  1. Download Tomcat, JDK, and MongoDB installation packages of the specific versions.

    1. Download JDK 1.8.

      Download address: https://www.oracle.com/java/technologies/jdk8-downloads.html.

    2. Download Tomcat 7.0 from http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz.
    3. Download MongoDB 3.2 from https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.9.tgz.

  2. Log in as user root to the device running Docker.
  3. Run the following commands to create the directory where the application is to be stored: For example, set the directory to apptest.

    mkdir apptest

    cd apptest

  4. Use Xshell to save the downloaded dependency files to the apptest directory.
  5. Run the following commands to decompress the dependency files:

    tar -zxf apache-tomcat-7.0.82.tar.gz

    tar -zxf jdk-8u151-linux-x64.tar.gz

    tar -zxf mongodb-linux-x86_64-rhel70-3.2.9.tgz

  6. Save the enterprise application (for example, apptest.war) in the webapps/apptest directory of the Tomcat runtime environment.

    apptest.war is used as an example only. Use your own application for actual configuration.

    mkdir -p apache-tomcat-7.0.82/webapps/apptest

    cp apptest.war apache-tomcat-7.0.82/webapps/apptest

    cd apache-tomcat-7.0.82/webapps/apptest

    ./../../../jdk1.8.0_151/bin/jar -xf apptest.war

    rm -rf apptest.war