COPY失败:stat/var/lib/docker/tmp/docker-xxx:没有这样的文件或目录 [英] COPY failed: stat /var/lib/docker/tmp/docker-xxx : no such file or directory
问题描述
我有一个github action工作流程来构建docker镜像:
I have a github actions workflow to build a docker image:
name: Backend-Demo Docker Image CI
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to Azure Container Registry
run: echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ${{ secrets.LOGIN_SERVER_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
- name: Get the version
id: vars
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
- name: Build the tagged Docker image
run: docker build . --file backend/Dockerfile --tag backend-demo/spring-boot:v1.0
Dockerfile是:
The Dockerfile is:
FROM openjdk:14-alpine
MAINTAINER example.com
RUN mkdir -p /opt/demo-0.0.1/lib
# Setting application source code working directory
WORKDIR /opt/demo-0.0.1/
COPY target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar
# ADD target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/
RUN sh -c 'touch demo-0.0.1-SNAPSHOT.jar'
ENTRYPOINT ["java"]
CMD ["-jar", "/opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar"]
但是当我执行此工作流程时,在 COPY
指令中出现了此错误:
But when I execute this workflow I got this error at the COPY
instruction:
Step 5/8 : COPY target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar
COPY failed: stat /var/lib/docker/tmp/docker-builder851513197/target/demo-0.0.1-SNAPSHOT.jar: no such file or directory
##[error]Process completed with exit code 1.
我一直在检查,当我们将文件 Dockerfile
保存在与我的指令不同的目录中时,它看起来是一个典型错误:
I have been checking and it looks a typical error when the file we have the Dockerfile
in a different directory like my instruction:
docker build.--file backend/Dockerfile --tag backend-demo/spring-boot:v1.0
我也没有 .dockerignore
文件,而我的Dockerfile恰好被称为 Dockerfile
.
I also don't have .dockerignore
file and my Dockerfile is called Dockerfile
precisely.
我要复制的 target/demo-0.0.1-SNAPSHOT.jar
文件存在于我的github存储库中不确定上下文会发生什么,但可能此答案可能是一个很好的提示?
The target/demo-0.0.1-SNAPSHOT.jar
file I am trying to copy is present in my github repository
Not sure what could be happening with the context, but probably this answer could be a good hint?
推荐答案
运行时
docker build . --file backend/Dockerfile ...
路径参数.
成为上下文目录.(Docker实际上会自己发送此目录树的副本,这是/var/lib/docker/tmp/...
路径的来源.) COPY
和 ADD
指令是相对于上下文目录的,而不是相对于Dockerfile的.
The path argument .
becomes the context directory. (Docker actually sends itself a copy of this directory tree, which is where the /var/lib/docker/tmp/...
path comes from.) The source arguments of COPY
and ADD
instructions are relative to the context directory, not relative to the Dockerfile.
如果您的源代码树看起来像
If your source tree looks like
.
+-- backend
| \-- Dockerfile
\-- target
\-- demo-0.0.1-SNAPSHOT.jar
与您显示的Dockerfile匹配的
.但是如果你有
that matches the Dockerfile you show. But if instead you have
.
+-- backend
+-- Dockerfile
\-- target
\-- demo-0.0.1-SNAPSHOT.jar
您会收到看到的错误.
如果您不需要引用上下文目录之外的任何内容,则只需更改要传递给 docker build
If you don't need to refer to anything outside of the context directory, you can just change what directory you're passing to docker build
COPY target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar
docker build backend ...
或者,如果您确实需要复制其他内容,则需要将 COPY
路径更改为相对于最高目录的路径.
Or, if you do have other content you need to copy in, you need to change the COPY
paths to be relative to the topmost directory.
COPY backend/target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar
COPY common/config/demo.yml /opt/demo-0.0.1/etc/demo.yml
docker build . -f backend/Dockerfile ...
这篇关于COPY失败:stat/var/lib/docker/tmp/docker-xxx:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!