Home > Java > javaTutorial > Analysis of the principles of docker in springboot

Analysis of the principles of docker in springboot

WBOY
Release: 2023-05-23 16:40:06
forward
895 people have browsed it

1. Add maven configuration

<properties>
    <docker.image.prefix>ms4t</docker.image.prefix>
  </properties>

  <build>
    <finalName>eureka</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
        <version>1.3.6</version>
        <configuration>
          <repository>${docker.image.prefix}/${project.artifactId}</repository>
          <buildArgs>
            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
          </buildArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>
Copy after login

2. Create Dockerfile

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Copy after login

Parameter explanation:

  • FROM : requires a base image, which can be public or private.

  • Subsequent builds will be based on this image. If multiple images are created in the same Dockerfile, multiple FROM instructions can be used

  • VOLUME configuration A directory with persistence function. A temporary file is created in the host /var/lib/docker directory and linked to the container’s /tmp. The modification step is optional, but it is necessary if it involves file system applications

  • . The /tmp directory is used to persist to the Docker data folder, because the embedded Tomcat container used by Spring Boot uses /tmp as the working directory by default

  • ARG sets the parameters added when compiling the image. ENV is to set the environment variable of the container

  • COPY: only supports copying local files to the container. There is also ADD which is more powerful but more complicated

  • ENTRYPOINT Command executed when the container starts

  • EXPOSE 8080 Exposed image port

##3. Build

mvn install dockerfile:build
Copy after login

4. Start

docker run -d --name 名称 -p 对外端口:容器端口 镜像ID
Copy after login

The above is the detailed content of Analysis of the principles of docker in springboot. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template