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 build a simple Java Web environment with Docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article focuses on "how to use Docker to build a simple Java Web environment", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Docker to build a simple Java Web environment.

Create a Java Web environment

Recently, the company is using Java Web to develop website applications, so it is necessary to understand how to use Docker to create the corresponding environment. Tomcat is the most important way to develop Java Web applications.

Use Tomcat mirroring

Tomcat is a Servlet container developed by the Jakarta project under the Apache Software Foundation. According to the technical specifications provided by Sun Microsystems, it supports Servlet and JavaServer Page (JSP), and provides some unique functions as a Web server, such as Tomcat management and control platform, security domain management and Tomcat valve. Because Tomcat itself contains a HTTP server, it can also be considered a separate Web server. However, you can't confuse Tomcat with an Apache HTTP server, which is a HTTP Web server implemented in C; the two HTTP web server are not bundled together. Apache Tomcat includes a configuration management tool, which can also be configured by editing a configuration file in XML format.

From https://zh.wikipedia.org/wiki/Apache_Tomcat

Using Tomcat mirroring is simple:

Docker run-it-p 8080-rm tomcat:8.0

The running results are as follows:

Use MySQL mirroring

It would be too low to write an article just using a Tomcat image. A website cannot avoid using a database, and Java applications are more appropriate to use their own brother, MySQL.

Starting an instance of MySQL is very simple:

Docker run-d-p 3306 MYSQL_DATABASE=yemeishu_database daocloud.io/mysql:latest 3306-e MYSQL_ROOT_PASSWORD=000000-e MYSQL_DATABASE=yemeishu_database daocloud.io/mysql:latest

Let's go to the container to see if the database: yemeishu_database has been created, and whether the password for root is set to: 000000.

If you use the database client, you can also see the database you created: yemeishu_database

Use JPress

JPress, a java replacement version of wordpress, is developed using JFinal. Support almost all functions similar to wordpress, such as templates, plug-ins and so on. At the same time, in the template, JPress put forward the concept of "template is the model", which makes it convenient for template producers to make business models flexibly, removes complicated functions such as widget, and is more flexible and concise than wordpress in the production of templates and plug-ins.

From https://github.com/JpressProjects/jpress

The goal of using JPress is to learn to work with MySQL containers and Tomcat containers to install and run JPress blogs.

Here, we mainly write the Dockerfile file and put the blog source file jpress.war (from the JPress official website) into the Tomcat container:

FROM tomcat:8.0

MAINTAINER yemeishu "yemeishu@126.com"

COPY jpress.war / usr/local/tomcat/webapps

Then execute the code to create a new image:

Docker build-t jpress:latest.

Then just create the container:

Docker run-d-p 8888purl 8080 jpress

Finally, just enter the URL: http://localhost:8888/jpress/ in the browser

If you stay at the last step after configuration, you can restart the container:

Docker restart cefe34ed2003

At this point, I believe you have a deeper understanding of "how to use Docker to build a simple Java Web environment". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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