docker - GitHub Action COPY 失败:未指定源文件
问题描述
配置 GitHub 操作以构建此项目的图像我收到此错误:
Step 5/7 : COPY /target/*.jar app.jar
COPY failed: no source files were specified
这是项目 Dockerfile,我从构建上下文路径引用文件,而不是从相对路径。
FROM openjdk:8-jdk-alpine as build
COPY . /usr/app
WORKDIR /usr/app
RUN chmod +x mvnw \
&& ./mvnw --version \
&& ./mvnw clean package
COPY /usr/app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
我已经验证了文件是否存在并使用ls -l /target
命令读取权限:
drwxr-xr-x 3 root root 4096 Oct 18 15:35 classes
drwxr-xr-x 3 root root 4096 Oct 18 15:35 generated-sources
drwxr-xr-x 3 root root 4096 Oct 18 15:35 generated-test-sources
-rw-r--r-- 1 root root 48625321 Oct 18 15:35 learning-spring-boot-0.0.1.jar
-rw-r--r-- 1 root root 33089 Oct 18 15:35 learning-spring-boot-0.0.1.jar.original
drwxr-xr-x 2 root root 4096 Oct 18 15:35 maven-archiver
drwxr-xr-x 3 root root 4096 Oct 18 15:35 maven-status
drwxr-xr-x 2 root root 4096 Oct 18 15:35 surefire-reports
drwxr-xr-x 3 root root 4096 Oct 18 15:35 test-classes
这是命令find .
后的输出./mvnw clean package
:
./target/learning-spring-boot-0.0.1.jar
./target/maven-archiver
./target/maven-archiver/pom.properties
./target/generated-sources
./target/generated-sources/annotations
./target/surefire-reports
使用相对路径在本地运行,但使用来自构建上下文的路径失败。
COPY /target/*.jar app.jar
这是项目网址。
我错过了什么?
解决方案
在我看来,您想使用多阶段 docker 构建,但您没有开始第二阶段。第二步COPY
不起作用,因为它仍处于同一阶段。就像 BMitch 提到的,在同一阶段,您只能使用 COPY 从构建上下文中复制。我对您进行了一些更改(从第二阶段开始,--from
在 COPY 中使用),Dockerfile
现在构建良好。Dockerfile 内容如下:
FROM openjdk:8-jdk-alpine as build
COPY . /usr/app
WORKDIR /usr/app
RUN chmod +x mvnw \
&& ./mvnw --version \
&& ./mvnw clean package
FROM openjdk:8-jre-alpine
COPY --from=build /usr/app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
推荐阅读
- python - 以元组为值按值对字典进行排序
- ios - 当我从 tableview 中删除行时,如何从 Firebase 中的数组中删除值?
- java - 在 SpringBoot 中使用重定向视图时如何隐藏查询参数?
- python-2.7 - 反向 geocding - geopy.Nominatim 模块引发 urlopen 错误 [SSL: UNKNOWN PROTOCOL]
- python - Python调用其他python函数错误?
- javascript - 数据库中的信息有多本地化?
- timer - STM32 定时器设置,用于去抖、短按和长按
- java - 用 Java 打印 HTML 文本
- ios - watchkit - 在忽略后台刷新时捕获
- python - 无法建立套接字连接