添加失败:stat /var/lib/docker/tmp/docker-builder673702145/target/xxx.jar:没有这样的文件或目录

时间:2018-09-23 12:02:55

标签: java docker spring-boot jar docker-image

尝试从openjdk基本映像创建docker映像时遇到以下问题。

ADD ${JAR_FILE} websocket-demo.jar
ADD failed: stat /var/lib/docker/tmp/docker-builder673702145/target/websocket-demo-0.0.1-SNAPSHOT.jar: no such file or directory

实际上,我在遵循this教程,并在尝试编译Docker文件时遇到了这个问题。

这是我的docker文件:

# Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine

# Add Maintainer Info
LABEL maintainer="Nuibb<*****@gmail.com>"

# Add a volume pointing to /tmp
VOLUME /tmp

# Make port 8080 available to the world outside this container
EXPOSE 8080

# The application's jar file
ARG JAR_FILE=target/websocket-demo-0.0.1-SNAPSHOT.jar

# Add the application's jar to the container
ADD ${JAR_FILE} websocket-demo.jar

# Run the jar file 
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/websocket-demo.jar"]

能否让我知道如何解决此问题?

3 个答案:

答案 0 :(得分:1)

https://medium.freecodecamp.org/dockerfile-copy-vs-add-key-differences-and-best-practices-9570c4592e9e

更改 @Override public boolean onQueryTextSubmit(String s) { Log.d("", "onQueryTextSubmit: "); search_list = new ArrayList<>(); search_list.clear(); Context context = getContext(); db = new dbhandler(mcontext); phoneList = new ArrayList<>(); phoneList = db.getAllPhoneContact(); String name; contact contact = new contact(); for (int i = 0; i < phoneList.size(); i++) { contact = phoneList.get(i); name = phoneList.get(i).getName(); if(name.contains(s)) { search_list.add(contact); } } allConAdapter = new AllConAdapter(getActivity(),search_list, 0); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(allConAdapter); allConAdapter.notifyDataSetChanged(); return true ; } private Context mcontext; @Override public void onAttach(Context context) { super.onAttach(context); mcontext = context ; Log.d("", "onAttach: "); } ADD ${JAR_FILE} websocket-demo.jar

答案 1 :(得分:0)

如果有人遇到这个问题并且犯了像我这样的非常业余的错误,我正在写这个答案。

我遇到了这个问题,因为我的pom.xml中有position:fixed,并试图在docker上下文中添加一个像这样的行(ADD $ {JAR_FILE} xxx-xxx.jar)的jar文件。

因此,一个简单的修复方法就是将pom.xml文件中的行更改为 <packaging>war</packaging>为我做到了。

答案 2 :(得分:0)

请尝试通过我认为创建.jar的路径(build / libs)指定jar文件

因此将代码更改为

    # Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine

# Add Maintainer Info
LABEL maintainer="Nuibb<*****@gmail.com>"

# Add a volume pointing to /tmp
VOLUME /tmp

# Make port 8080 available to the world outside this container
EXPOSE 8080

# The application's jar file
ARG JAR_FILE=build/libs/websocket-demo-0.0.1-SNAPSHOT.jar

# Add the application's jar to the container
ADD ${JAR_FILE} websocket-demo-0.0.1-SNAPSHOT.jar

# Run the jar file 
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/websocket-demo-0.0.1-SNAPSHOT.jar"]