Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to containerize MyBank

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to containerize MyBank". In daily operation, I believe many people have doubts about how to containerize MyBank. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to containerize MyBank"! Next, please follow the editor to study!

Example: containerize a simple Java Web application-MyBank.

It contains static resource files such as Java source code, JSP files, pictures, and CSS.

The project structure of MyBank is based on the required deployment of Maven. Through Maven, you can compile and build the deployment package of MyBank-WAR package.

Like other applications, during the development process, MyBank's source code is uploaded to the configuration management library for version control, and the configuration management server used here is GitHub.

1. Install the deployment source code tool Git.

# yum-y install git

two。 Download the Java application source code for the example from GitHub.

[root@master ~] # cd / opt/ [root@master opt] # git clone https://github.com/nichochen/mybank-demo-maven

3. Prepare to compile and build the environment. Install the Java development kit JDK and the build tool Maven required for application construction

# yum-y install maven

4. Compile and build applications through build tools.

# cd mybank-demo-maven/ [root@master mybank-demo-maven] # mvn package

After building, a WAR package ROOT.war. WAR will be generated in the target directory.

# ls target/classes maven-archiver ROOT ROOT.war surefire surefire-reports test-classes

5. Select the basic container image that meets the requirements of the application, or install and build from the basic operating system image.

# docker pull tomcat:7.0.70-jre7-alpine

6. Write Dockerfile. Copy the built application deployment package to the release directory. An example of Dockerfile is as follows:

# cat Dockerfile FROM tomcat:7.0.70-jre7-alpineADD. / target/ROOT.war / usr/local/tomcat/webapps/mybank.war

7. Execute Docker Build to build the image. Life the mirror as mybank-tomcat. In the case of a request without specifying a mirrored tag, the default label is latest.

# docker build-t mybank-tomcatbank-tomcat.

After building, you can see the new image generated by Docker Build

# docker images | grep mybank-tomcatmybank-tomcat latest 0a46e831b130 2 days ago 150 MB

8. Test the image. Test the newly created image with the docker run command. The parameter-p 8080virtual 8080 maps port 8080 of the container to port 8080 of the host.

# docker run-it-- rm-p 8080 mybank-tomcat

When finished, visit MyBank's home page test through a browser.

# oc get serviceNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEhello-openshift ClusterIP 172.30.242.25 80 80max TCP 8888TCP 3D

9. Push the image. After the test is passed, the image will be published to the appropriate image repository.

# docker tag mybank-tomcat:latest 192.168.100.133:5000/mybank-tomcat:latest# docker push 192.168.100.133:5000/mybank-tomcat:latest at this point, the study on "how to containerize MyBank" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report