Container technology, Docker, virtualization — these terms have been around for a long time, but they’re still very popular in cloud native development. Even ABAP Netweaver, the company that SAP made its name with, is now embracing containerization in the cloud, as in this blog post from the SAP community:

Proof of Concept: Deploying ABAP in Kubernetes

Let’s skip ABAP containerization today and start with the simplest concept. There are so many technical articles about Docker containers on the Internet, Jerry will not repeat them, I will stick to SAP technology and SAP solutions.

If you have a working Java application, can you deploy it as a Docker container and run it on SAP cloud platform? Sure, and it only takes a few simple command lines.

The next steps in this article are for those of you who have heard of Docker container technology, but haven’t yet tried it out. Read this article to get an overview of the steps for containerizing and deploying Java applications to run on the SAP cloud platform. You can also follow the steps in this article to try it out. Just build a simple Java development environment locally, install Docker client, and apply for a TRIAL account on SAP cloud platform.

(1) You must first have a SpringBoot application that can run properly locally. If not, Baidu and then do one yourself.

If you really don’t want to do it yourself, you can clone it from Jerry’s Github repository:

After you have configured Maven and JDK locally, start it directly from the command line:

mvn spring-boot:run

You will see Tomcat started on port 8000, meaning that the application has been successfully started, listening on local port 8000.

Localhost :8000/product: Hello World. Now that we have a local working SpringBoot application, the next step is to package it as a Docker image.

(2) Create a new file called Dockerfile in the SpringBoot project and enter the following content:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
VOLUME /log
EXPOSE 8080
ADD target/prolikeService.jar app.jar
ENV JAVA_OPTS="-Dserver.port=8080"
ENTRYPOINT exec java $JAVA_OPTS -jar /app.jar
Copy the code

This is actually an instruction file, and the Docker client will make a Docker image based on the contents of the file.

Briefly describe the meaning of each line.

First line: Specifies that the image to be made is based on an image called OpenJDK: 8-JDK-alpine, about which you can find more information on the Docker Hub website: hub.docker.com/_/openjdk

Line 2 and line 3: Define two persistent stores named TMP and log. Data generated during the runtime of a container is destroyed when the container is destroyed. However, sometimes we want to keep this data persistent. For example, if we need to analyze the log files generated during the runtime of a container, we can use the container persistence technology provided by the VOLUME keyword in Dockerfile to create a so-called VOLUME. Map the directory to which the container application writes data while running to a directory on the host.

If a container is still running, we can use the command line to go inside the container and view the run log files in the log folder

docker exec -it 8302db78f838 /bin/sh

If the container has been destroyed, go to the /var/lib/docker-volumes directory on the host to view the persistent log files:

Line 6 ~ 7: Set JVM startup parameters to expose port 8080 to the outside world.

After the Dockerfile file is written, use the command line to create an image:

docker build -t i042416/springbootexample:v1 .

V1 represents the label of the image, and the period at the end of the command line represents the current directory.

After the image is made, use the command line to push the image to the Docker Hub website (a bit like submitting code to Github with git client) :

docker push i042416/springbootexample:v1

After success, you can see the pushed image on Docker Hub:

Hub.docker.com/repository/…

This way, SAP cloud platform can pull the image from Docker Hub later.

(3) Log in to SAP cloud platform CloudFoundry environment, use command line deployment, specify the image name we just uploaded to Docker Hub with parameter — Docker-image, and the generated application is named JerryJavadocker.

cf push jerryjavadocker –docker-image i042416/springbootexample:v6

Because my container image was changed several times, the label was increased from V1 to v6.

The status of the application is running after successful deployment:

You can also see this successfully deployed application running on the SAP cloud platform:

Running the successfully deployed Docker application will have the same effect as our local MVN Spring-boot :run. At this point, the containerization of the SpringBoot application and the deployment of the SAP cloud platform are successful.

By the way, yesterday Jerry posted an article about SAP Business Application Studio, a new generation of full-stack development tools for SAP.

Jerry will write a short article about how traditional ABAP developers can learn SAP Cloud Platform technologies.

Thanks for reading.

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: