Containerizing a Java application on Linux - AWS App2Container

Containerizing a Java application on Linux

This tutorial takes you through the steps to containerize a legacy Java application on Linux using App2Container, and to deploy it on Amazon ECS or Amazon EKS. You can complete all steps on the application server, or you can perform the initial steps on the application server and perform the containerization and deployment steps on a worker machine.

Prerequisites

Verify that you have completed the following prerequisites:

  • You installed the AWS CLI and configured the AWS profile on your server. See Configure the AWS profile in the Setting up section of this user guide for more information.

  • You installed the Docker engine on the server where you are running containerization and deployment steps. See Install the Docker engine in the Setting up section of this user guide for more information.

  • There are one or more Java applications running on the application server.

  • You have root access on the application server (and worker machine, if using).

  • The application server (and worker machine, if using) has tar and 20 GB of free space.

Step 1: Install App2Container

App2Container for Linux is packaged as a tar.gz archive. The archive contains an interactive shell script that installs App2Container on your server. If you are using an application server and a worker machine, you must install App2Container on both.

To download and install App2Container for Linux

  1. Download the installation file in one of the following ways:

    • Use the curl command to download the App2Container installation package from Amazon S3.

      $ curl -o AWSApp2Container-installer-linux.tar.gz https://app2container-release-us-east-1.s3.us-east-1.amazonaws.com/latest/linux/AWSApp2Container-installer-linux.tar.gz
    • Use your browser to download the installer from the following URL: https://app2container-release-us-east-1.s3.us-east-1.amazonaws.com/latest/linux/AWSApp2Container-installer-linux.tar.gz.

  2. Extract the package to a local folder on the server.

    $ sudo tar xvf AWSApp2Container-installer-linux.tar.gz
  3. Run the install script that you extracted from the package and follow the prompts.

    $ sudo ./install.sh

You can check the downloaded tar.gz installer archive for integrity by validating the MD5 and SHA256 hashes of the local file against the published hash files.

To verify the authenticity of the download

  1. Generate hashes to verify

    From the directory where you downloaded your tar.gz installer, run the following commands to generate the hash of the downloaded tar.gz file.

    $ md5sum AWSApp2Container-installer-linux.tar.gz a0a1234f567bf89012345a6ce7bf89a0 AWSAppContainerization-installer-linux.tar.gz $ sha256sum AWSApp2Container-installer-linux.tar.gz 01bc2d345f6789012345bd6aa789012345d67dea8b9c0f1234ee5a67890123d4 AWSAppContainerization-installer-linux.tar.gz
  2. Verify hashes against public files

    Download the App2Container hash files from Amazon S3 using the following links, and compare the contents to the hashes that you generated in step 1:

Step 2: Initialize App2Container

On each server where you installed App2Container, run the init command as follows.

$ sudo app2container init

You are prompted to provide the following information. Choose <enter> to accept the default value.

  • Workspace directory path - A local directory where App2Container can store artifacts during the containerization process. The default is /root/app2container.

  • AWS profile - Contains information needed to run App2Container, such as your AWS access keys. For more information, see Configure the AWS profile. Your AWS defalt profile is used if you don't specify another value.

  • Amazon S3 bucket - You can optionally provide the name of an Amazon S3 bucket where you can extract artifacts using the extract command. The containerize command uses the extracted components to create the application container if the Amazon S3 bucket is configured. The default is no bucket.

  • Permission to collect usage metrics - You can optionally allow App2Container to collect information about the host operating system, application type, and the app2container commands that you run. The default is to allow the collection of metrics.

  • Whether to enforce signed images - You can optionally require that images are signed using Docker Content Trust (DCT). The default is no.

Step 3: Analyze your application

On the application server, use the following procedure to prepare to containerize the application.

To prepare for containerization

  1. Run the inventory command as follows to list the Java applications that are running on your server.

    $ sudo app2container inventory

    The output includes a JSON object collection with one entry for each application. Each application object will include key/value pairs as shown in the following example.

    "java-app-id": { "processId": pid, "cmdline": "/user/bin/java ...", "applicationType": "java-apptype" }
  2. Locate the application ID for the application to convert in the JSON output of the inventory command, and then run the analyze command as follows, replacing java-app-id with the application ID that you located.

    $ sudo app2container analyze --application-id java-app-id

    The output is a JSON file, analysis.json, stored in the workspace directory that you specified when you ran the init command.

  3. (Optional) You can edit the information in the containerParameters section of analysis.json as needed before continuing to the next step.

Step 4: Transform your application

The transform phase depends on whether you are running all steps on the application server, or are using the application server for the analysis and a worker machine for containerization and deployment.

To containerize the application on the application server

If you are using an application server for all steps, run the containerize command as follows.

$ sudo app2container containerize --application-id java-app-id

The output is a set of deployment files that are stored in the workspace directory that you specified when you ran the init command.

To containerize the application on a worker machine

If you are using a worker machine for containerization and deployment, use the following procedure to transform the application.

  1. On the application server, run the extract command as follows.

    $ sudo app2container extract --application-id java-app-id
  2. If you specified an Amazon S3 bucket when you ran the init command, the archive is extracted to that location. Otherwise, you can manually copy the resulting archive file to the worker machine.

  3. On the worker machine, run the containerize command as follows.

    $ sudo app2container containerize --input-archive /path/extraction-file.tar

    The output is a set of deployment artifacts that are stored in the workspace directory that you specified when you ran the init command.

Step 5: Deploy your application

Review the deployment artifacts generated in the previous step and modify them as needed. Run the generate app-deploy command as follows to deploy the application on AWS.

$ sudo app2container generate app-deployment --deploy --application-id java-app-id

Step 6: Clean up

To remove App2Container from your application server or worker machine, delete the /usr/local/app2container folder where it is installed, and then remove this folder from your path.