Java 运行docker映像时无法到达端点
我遵循一个关于如何将maven springboot服务器docker化的指南,我可以使用“winpty docker run-it-p 9999:8080 springio/spring docker template”成功运行docker映像,但我无法访问它的任何端点。即使输出指示Spring Boot正在运行 我尝试了localhost:8080/users/all和localhost:9999/users/all 如果我使用“/mvnw-package&&java-jar-target/spring-docker-template-0.1.0.jar”正常运行应用程序,那么端点工作正常 DockerfileJava 运行docker映像时无法到达端点,java,docker,spring-boot-maven-plugin,Java,Docker,Spring Boot Maven Plugin,我遵循一个关于如何将maven springboot服务器docker化的指南,我可以使用“winpty docker run-it-p 9999:8080 springio/spring docker template”成功运行docker映像,但我无法访问它的任何端点。即使输出指示Spring Boot正在运行 我尝试了localhost:8080/users/all和localhost:9999/users/all 如果我使用“/mvnw-package&&java-jar-target/
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","main.Application"]
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>spring-docker-template</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>main.Application</start-class>
<java.version>1.8</java.version>
<!-- docker image prefix -->
<docker.image.prefix>springio</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--docker -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<configuration>
<!-- In this creates creates: springio/spring-docker-template -->
<repository>${docker.image.prefix}/${project.artifactId}</repository>
</configuration>
</plugin>
<!-- Ensures that the jar is unpacked before the docker image -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
org.springframework
尝试将EXPOSE命令添加到dockerfile,可能是因为它没有公开端口8080,因此您无法访问它
更改的Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
EXPOSE 8080
ENTRYPOINT ["java","-cp","app:app/lib/*","main.Application"]
再次构建映像,然后再次尝试以下步骤。尝试了它,然后执行了“/mvnw安装dockerfile:Build”和“docker运行-it-p 8080:8080 springio/spring docker模板”。问题仍然存在。您提到winpty,因此看起来您正在windows上运行。如果您在windows上运行docker toolbox,那么您需要使用192.168.99.100 ip地址而不是LocalHost您是一个救生员!