Dockerized春季启动Web服务引发FileNotFound异常

时间:2019-07-04 10:15:40

标签: spring-boot docker dockerfile docker-container file-not-found

我尝试使用Docker File Command将文件从Windows计算机复制到Docker容器,并从spring Web service读取这些文件。 Webservice抛出未找到的错误文件!

在这里,我正在尝试将本地目录src / nlp复制到/ data容器Directoty

下面是可用的docker卷

enter image description here

Docker文件

FROM openjdk:8-jdk-alpine

EXPOSE 8080

ARG JAR_FILE=/target/nlp-0.0.1-SNAPSHOT.jar

ADD ${JAR_FILE} nlp-0.0.1-SNAPSHOT.jar

ADD src/nlp  /data

ENTRYPOINT ["java","-jar", "nlp-0.0.1-SNAPSHOT.jar"]`

application.properties

server.port=8080
logging.level.radial.nlp=DEBUG
logging.file = mylogfile.log
nlp.learning.dir = /data/

Java

InputStream inputStream = new FileInputStream(environment.getProperty("nlp.learning.dir")+ "/train/models/en/token/en-token.bin"); 

错误

java.io.FileNotFoundException: /data/train/models/en/token/en-token.bin (No such file or directory)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)

3 个答案:

答案 0 :(得分:1)

train 目录之前,请注意路径中的其他斜线 /data//train/models/en/token/en-token.bin

考虑将阅读行更改为:

InputStream inputStream = new FileInputStream(environment.getProperty("nlp.learning.dir")+ "train/models/en/token/en-token.bin");

答案 1 :(得分:0)

很可能您没有文件src/nlp/train/models/en/token/en-token.bin与要从中构建容器的目录相同。

parent/
├── Dockerfile
└── src/
    └── nlp/
        └── train/
            └── models/
                └── en/
                    └── token/
                        └── en-token.bin <--- does this exist?

答案 2 :(得分:0)

我已经更改了我的maven插件依赖项,现在它可以正常工作

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.7</version>
<!-- Wire up to the default build phases -->
<executions>
  <execution>
    <id>default</id>
    <goals>
      <goal>build</goal>
      <goal>push</goal>
    </goals>
  </execution>
</executions>
<configuration>
  <repository>${project.artifactId}</repository>
  <buildArgs>
    <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
  </buildArgs>
</configuration>