search
HomeJavajavaTutorialHow SpringBoot packages docker images for release

1: First build a SpringBoot project

Only need to add web dependencies

2: Write a controller for testing

How SpringBoot packages docker images for release

3: Start the local machine and observe whether it can successfully access

How SpringBoot packages docker images for release

##4: Packaging

How SpringBoot packages docker images for release

How SpringBoot packages docker images for release

5: Find the location of the generated jar package

How SpringBoot packages docker images for release

How SpringBoot packages docker images for release

6: Start running test of the jar package

How SpringBoot packages docker images for release

How SpringBoot packages docker images for release

7: Write the Dockerfile file

How SpringBoot packages docker images for release##8: Upload our jar package and Dockerfile file to the server

How SpringBoot packages docker images for release9: Use the uploaded file to build the image

[root@iZwz9hv1phm24s3jicy8x1Z idea]# ls
Dockerfile  Docker-Package-0.0.1-SNAPSHOT.jar
[root@iZwz9hv1phm24s3jicy8x1Z idea]# docker build -t dongmu-springboot-project .
Sending build context to Docker daemon  17.54MB
Step 1/5 : FROM java:8
8: Pulling from library/java
5040bd298390: Pull complete 
fce5728aad85: Pull complete 
76610ec20bf5: Pull complete 
60170fec2151: Pull complete 
e98f73de8f0d: Pull complete 
11f7af24ed9c: Pull complete 
49e2d6393f32: Pull complete 
bb9cdec9c7f3: Pull complete 
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image for java:8
 ---> d23bdf5b1b1b
Step 2/5 : COPY /*.jar /app.jar
 ---> a16d648390df
Step 3/5 : CMD ["--server.port=8080"]
 ---> Running in bc45f72484c7
Removing intermediate container bc45f72484c7
 ---> 713861b331ad
Step 4/5 : EXPOSE 8080
 ---> Running in 7a28e4939b5e
Removing intermediate container 7a28e4939b5e
 ---> 08f540832166
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
 ---> Running in 6cd669cd522c
Removing intermediate container 6cd669cd522c
 ---> 1fd9f50df534
Successfully built 1fd9f50df534
Successfully tagged dongmu-springboot-project:latest

10: Use the image to run the container

[root@iZwz9hv1phm24s3jicy8x1Z idea]# docker images
REPOSITORY                  TAG                IMAGE ID       CREATED              SIZE
dongmu-springboot-project   latest             1fd9f50df534   About a minute ago   661MB
redis                       5.0.9-alpine3.11   3661c84ee9d0   24 months ago        29.8MB
tomcat                      9.0.22             c856951ade0a   2 years ago          624MB
java                        8                  d23bdf5b1b1b   5 years ago          643MB
[root@iZwz9hv1phm24s3jicy8x1Z idea]# docker run -d -P --name dongmu-springboot-web dongmu-springboot-project
c63282034de4e9dca727c93009e29f421bcd2544557a60b6339fa8056cc1d0d5

11: Test access

[root@iZwz9hv1phm24s3jicy8x1Z idea]# docker ps
CONTAINER ID   IMAGE                       COMMAND                  CREATED          STATUS          PORTS                                         NAMES
c63282034de4   dongmu-springboot-project   "java -jar /app.jar …"   34 seconds ago   Up 33 seconds   0.0.0.0:49166->8080/tcp, :::49166->8080/tcp   dongmu-springboot-web
[root@iZwz9hv1phm24s3jicy8x1Z idea]# curl localhost 49166
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Apache Tomcat/9.0.50</title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>
......
访问成功

The above is internal access, let’s restart and use the external network to access

[root@iZwz9hv1phm24s3jicy8x1Z idea]# docker run -d -p 3344:8080 --name dongmu-springboot-web dongmu-springboot-project
35f3b4fe0f9a4b878d6566a9f4334fc98e7841b1fc5eb7869dd0044d4fb44d6d

The above is the detailed content of How SpringBoot packages docker images for release. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
What are the benefits of Java's platform independence for developers?What are the benefits of Java's platform independence for developers?May 03, 2025 am 12:15 AM

Java'splatformindependenceissignificantbecauseitallowsdeveloperstowritecodeonceandrunitonanyplatformwithaJVM.This"writeonce,runanywhere"(WORA)approachoffers:1)Cross-platformcompatibility,enablingdeploymentacrossdifferentOSwithoutissues;2)Re

What are the advantages of using Java for web applications that need to run on different servers?What are the advantages of using Java for web applications that need to run on different servers?May 03, 2025 am 12:13 AM

Java is suitable for developing cross-server web applications. 1) Java's "write once, run everywhere" philosophy makes its code run on any platform that supports JVM. 2) Java has a rich ecosystem, including tools such as Spring and Hibernate, to simplify the development process. 3) Java performs excellently in performance and security, providing efficient memory management and strong security guarantees.

How does the JVM contribute to Java's 'write once, run anywhere' (WORA) capability?How does the JVM contribute to Java's 'write once, run anywhere' (WORA) capability?May 02, 2025 am 12:25 AM

JVM implements the WORA features of Java through bytecode interpretation, platform-independent APIs and dynamic class loading: 1. Bytecode is interpreted as machine code to ensure cross-platform operation; 2. Standard API abstract operating system differences; 3. Classes are loaded dynamically at runtime to ensure consistency.

How do newer versions of Java address platform-specific issues?How do newer versions of Java address platform-specific issues?May 02, 2025 am 12:18 AM

The latest version of Java effectively solves platform-specific problems through JVM optimization, standard library improvements and third-party library support. 1) JVM optimization, such as Java11's ZGC improves garbage collection performance. 2) Standard library improvements, such as Java9's module system reducing platform-related problems. 3) Third-party libraries provide platform-optimized versions, such as OpenCV.

Explain the process of bytecode verification performed by the JVM.Explain the process of bytecode verification performed by the JVM.May 02, 2025 am 12:18 AM

The JVM's bytecode verification process includes four key steps: 1) Check whether the class file format complies with the specifications, 2) Verify the validity and correctness of the bytecode instructions, 3) Perform data flow analysis to ensure type safety, and 4) Balancing the thoroughness and performance of verification. Through these steps, the JVM ensures that only secure, correct bytecode is executed, thereby protecting the integrity and security of the program.

How does platform independence simplify deployment of Java applications?How does platform independence simplify deployment of Java applications?May 02, 2025 am 12:15 AM

Java'splatformindependenceallowsapplicationstorunonanyoperatingsystemwithaJVM.1)Singlecodebase:writeandcompileonceforallplatforms.2)Easyupdates:updatebytecodeforsimultaneousdeployment.3)Testingefficiency:testononeplatformforuniversalbehavior.4)Scalab

How has Java's platform independence evolved over time?How has Java's platform independence evolved over time?May 02, 2025 am 12:12 AM

Java's platform independence is continuously enhanced through technologies such as JVM, JIT compilation, standardization, generics, lambda expressions and ProjectPanama. Since the 1990s, Java has evolved from basic JVM to high-performance modern JVM, ensuring consistency and efficiency of code across different platforms.

What are some strategies for mitigating platform-specific issues in Java applications?What are some strategies for mitigating platform-specific issues in Java applications?May 01, 2025 am 12:20 AM

How does Java alleviate platform-specific problems? Java implements platform-independent through JVM and standard libraries. 1) Use bytecode and JVM to abstract the operating system differences; 2) The standard library provides cross-platform APIs, such as Paths class processing file paths, and Charset class processing character encoding; 3) Use configuration files and multi-platform testing in actual projects for optimization and debugging.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft