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 redefine Java Virtualization deployment with Docker

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article focuses on "how to redefine Java virtualization deployment with Docker". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to redefine Java virtualization deployment with Docker.

Docker is an open source platform for building, distributing, and running distributed applications. Dockerized applications can be run on developers' computers and can be deployed to production cloud environments, and Docker is playing a huge role in continuous integration and deployment in an unprecedented way. Xi Yun believes that Docker is a platform that every developer should be familiar with in the future work.

The open source Java project brings Docker to Java developers. Later, we will explain why Docker is so important to Java developers, guide you to install and deploy Java applications in Docker, and show you how to integrate Docker into the build process.

Docker Technology Quick Guide

Docker has its own terminology, which will be used repeatedly in this article, so take some time to familiarize yourself with them:

Docker engine (Docker engine): a daemon on the server that serves as a bridge between you and the Docker application and the operating system you depend on.

Dockerfile: a text file containing instructions for building a Docker image.

Docker image: a product of building a Dockerfile, and executing the commands in Dockerfile during the build process will generate an image. It is first built on a root system (base image), then installs the application, and then executes a series of commands to prepare the environment for launching the application. As the basis of the Docker container, the Docker image is equivalent to a static module of the container.

Docker container: a runtime instance of a Docker image. The Docker image is similar to the concept of a module (built from Dockerfile, this Dockerfile contains the root system, the application, and a series of commands to build the image). The container is an actual running instance of that image.

Docker host: a physical machine or virtual machine on which the Docker engine runs and maintains the Dockerhub on which the container depends.

DockerHub: the official Docker image repository. Think of DockerHub as a GitHub repository, a central repository for Git, and a central repository for official storage and provision of Docker images.

CSphereHub: Xiyun's official Docker micro-image warehouse. There are many images in DockerHub, but carefully selected and carefully crafted images are stored in cSphereHub.

Introduction to Docker

More than twenty years ago, software applications were so large and complex that they were deployed on large computers. In the world of Java, we develop an enterprise software package (EAR) that contains enterprise JavaBean (EJB) and web components (WAR), which are then deployed on large application servers. In order to use the resources on these mainframe computers as efficiently as possible, we will try our best to design these applications.

In the early 21st century, with the advent of cloud computing, developers began to use virtual machines and server clusters to expand applications to meet demand. To deploy applications in a virtualized way, applications must be designed to be different from traditional methods, and lightweight, object-oriented applications become the new standard. We learned to make the software into a collection of interconnected services and to design the components as stateless as possible. The concept and implementation of extensible architecture have changed. Instead of relying on the vertical scaling of a single mainframe computer, developers and architects begin to think about how to implement it horizontally: how to deploy a single application to several lightweight computers.

The emergence of Docker makes virtualization a step forward, providing a lightweight layer between the application and the dependent hardware. Docker runs the application as a process of the host system. Figure 1 compares traditional virtual machines with Docker.

Figure 1. Comparison between Virtual Machine and Docker

The traditional virtual machine runs a virtual machine monitor in the host system, and runs a complete client system (GuestOS) in the virtual machine, and all the packages that the application depends on are in the customer system.

In contrast, Docker has a Docker engine, which is also a daemon running on the host system. The Docker engine translates the system calls in the Docker container into native calls to the host system. A Docker image, as a template for creating a Docker container, contains only the smallest layer of the operating system and only the dependent libraries needed by the application.

These differences may not seem like much, but in fact they are very different. A large part of the advantages of Docker are reflected in this point!

> > understanding process Virtualization

If we take a closer look at the operating system in the virtual machine, we will notice the resources in the virtual machine, such as CPU and memory. But when we run a Docker container, we see the resources on the host directly. I see Docker as a process-level virtualization platform, not a system-level virtualization platform. Basically, the application runs on the host as an independent self-contained process. Docker achieves isolation with the help of several powerful components on Linux, ensuring that each process is an independent process on the operating system.

Because the Dockerized application runs in a similar way to the process on the host, the design is also different from the application in the virtual machine. For example, we usually run Tomcat and MySQL databases on a virtual machine, but in the practice of Docker, we deploy the app server and the database separately, running in different containers. This allows Docker to better manage individual units on the host system, which means that to use Docker more efficiently, we need to design applications with appropriate granularity, such as micro-services.

Micro services in Docker

To put it simply, micro-service is an architectural way to promote system modularization. In the micro-service architecture, complex applications are composed of smaller independent processes, each process has one or more specific functions, and applications communicate with language-independent API and other processes.

Microservices provide one or more related functions through a very small granularity and highly decoupled set of services. For example, if you are managing a user center and shopping cart, you are likely to choose to design them as separate services, such as a user center service and a shopping cart service, rather than packing two modules into a package to run as a single service. More specifically, using microservices means building web services, the most common [RESTful web service], and grouping them by function. In Java, we package these services into WAR packages, deploy them to a container, such as Tomcat, and then run the services in the Tomcat and Docker containers.

> install Docker

Before we delve into Docker, let's set up the local environment. If you are using Linux, that's great, you can install and run Docker directly. For those using Windows or Mac, Docker can be used through a tool called Docker Toolbox, which installs a virtual machine (Virtual Box using Oracle) that runs a Linux system containing Docker daemons. We can use the Docker client to send instructions to the daemon for processing. Note that you don't need to manage the virtual machine, just install the tool and execute the Docker command line tool.

Start downloading Docker from the corresponding document [Mac], [Windows], or [Linux].

My computer is Mac, so I downloaded and ran the Mac version of the Docker Toolbox installation package, and then I ran the Docker Quickstart terminal, which started a Virtual Box image and a command line terminal. This installation process is basically the same as in Windows. For more information, please refer to the Windows version of the documentation.

> DockerHub: image repository of Docker

Before we start using Docker, take a few minutes to visit [cSphereHub] (https://csphere.cn/hub/), the image repository). Take a look at cSphereHub and you will find several carefully selected micro-mirrors on it. If you use the cSphere management platform, after adding the * * micro-image repository * *, the repository contains some official images of docker. There are basic systems in the image repository, such as Alpine, Ubuntu, or Java-related systems such as Tomcat, jdk, jre, etc. You can also find almost all popular applications on it, including MySQL, MongoDB, Neo4j, Redis, Memcached, Postgres, Nginx, Node.js, WordPress, PHP, Perl, Ruby and so on. Before you plan to build a new image on your own, please make sure that it is available on cSphereHub or DockerHub.

As an exercise, let's run a simple CentOS image and type in the command line of Docker Toolbox:

```sh

$docker run-it centos

`

This docker command is your primary interface to the Docker daemon. The run instruction tells Docker to download and run the specified image (assuming it doesn't already exist locally). Alternatively, you can download an image directly with the pull command without running it. There are two parameters: I will have Docker run in interactive mode, and t will have it create a TTY terminal. Note that the unofficial image uses the established format "user name / image name", while the official image omits the user name, so we only need to specify "centos" to run the image. Alternatively, you can add ": version number" to the image name to specify the version number, for example, centos:7. Each image uses the latest version by default, and the current CentOS version number is 7. 0.

After running $docker run-it centos, you will see that Docker starts downloading the image, and when it is finished, you will see output similar to the following:

```sh

$docker run-it centos

[root@dcd69de89aad /] #

`

Because we are running in interactive mode, it displays a shell command prompt for the root user. Take a look at the system and log out using exit.

You can use the docker images command to view the downloaded images on the system:

```sh

$docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

Java 8 5282faca75e8 4 weeks ago 817.6 MB

Tomcat latest 71093fb71661 8 weeks ago 347.7 MB

Centos latest 7322fbe74aa5 11 weeks ago 172.2 MB

`

You can see that I already have the latest versions of CentOS, Tomcat and Java 8.

To be continued.

At this point, I believe you have a deeper understanding of "how to redefine Java virtualization deployment with Docker". 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