Table of Contents
1: First build a SpringBoot project
2: Write a controller for testing
3: Start the local machine and observe whether it can successfully access
10: Use the image to run the container
11: Test access
The above is internal access, let’s restart and use the external network to access
Home Java javaTutorial How SpringBoot packages docker images for release

How SpringBoot packages docker images for release

May 24, 2023 pm 06:31 PM
docker springboot

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
Copy after login

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
Copy after login

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>
......
访问成功
Copy after login

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
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to exit the container by docker How to exit the container by docker Apr 15, 2025 pm 12:15 PM

Four ways to exit Docker container: Use Ctrl D in the container terminal Enter exit command in the container terminal Use docker stop &lt;container_name&gt; Command Use docker kill &lt;container_name&gt; command in the host terminal (force exit)

How to copy files in docker to outside How to copy files in docker to outside Apr 15, 2025 pm 12:12 PM

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] &lt;Container Path&gt; &lt;Host Path&gt;. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to restart docker How to restart docker Apr 15, 2025 pm 12:06 PM

How to restart the Docker container: get the container ID (docker ps); stop the container (docker stop &lt;container_id&gt;); start the container (docker start &lt;container_id&gt;); verify that the restart is successful (docker ps). Other methods: Docker Compose (docker-compose restart) or Docker API (see Docker documentation).

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to update the image of docker How to update the image of docker Apr 15, 2025 pm 12:03 PM

The steps to update a Docker image are as follows: Pull the latest image tag New image Delete the old image for a specific tag (optional) Restart the container (if needed)

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

See all articles