Step 2: Preparing the Application Runtime Environment
After application analysis, you have gained the understanding of the OS and runtime environment required by the application. You need to prepare these environments.
- Installing Docker: During application containerization, you need to build a Docker image. To do so, you have to prepare a PC and install Docker on it.
- Obtaining the base image version: 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 Docker Hub.
- Obtaining the runtime environment: Obtain the runtime environment of the application and the MongoDB database with which the application interconnects.
Docker can nearly be installed on all OSs. You can select the Docker version to be installed as required. For more information, see https://docs.docker.com/engine/installation/.
HUAWEI CLOUD SWR uses Docker 1.11.2 or later to upload images.
- Log in as the root user to the device on which Docker is about to be installed.
- Run the following commands to quickly install Docker on the device running Linux:
curl -fsSL get.docker.com -o get-docker.sh
- Run the following command to query the Docker version:
Client: Version: 17.12.0-ce API Version:1.35 ...
Version indicates the version number.
Obtaining the Base Image Version
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 Docker Hub.
Search for the image version based on the OS on which the application runs.
- Log in to https://hub.docker.com/.
- Search for CentOS. The image corresponding to CentOS 7.1 is centos7.1.1503. You need to use this image name when compiling the Dockerfile.
Figure 1 Obtaining the CentOS version
Obtaining the Runtime Environment
In this example, the web application of the Tomcat type is used. This application requires the runtime environment 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.
- Download Tomcat, JDK, and MongoDB installation packages of the specific versions.
- Download JDK 1.8 from http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html.
- Download Tomcat 7.0 from https://tomcat.apache.org/download-70.cgi.
- Download MongoDB 3.2 from https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.9.tgz.
- Log in as the root user to the device running Docker.
- Run the following commands to create the directory where the application is to be stored: For example, set the directory to testapp.
- Use XShell to save the downloaded dependency files to the testapp directory.
- 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
- Save the enterprise application (for example, apptest.war) in the webapps/apptest directory of the Tomcat runtime environment.
In this example, no application packages are provided. Therefore, this step cannot be performed.
mkdir -p apache-tomcat-7.0.82/webapps/apptest
cp apptest.war apache-tomcat-7.0.82/webapps/apptest
./../../../jdk1.8.0_151/bin/jar -xf apptest.war
rm -rf awcp.war