复制失败:stat/var/lib/docker/tmp/docker-xxx:没有这样的文件或目录 [英] COPY failed: stat /var/lib/docker/tmp/docker-xxx : no such file or directory

查看:18
本文介绍了复制失败:stat/var/lib/docker/tmp/docker-xxx:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 github 操作工作流来构建 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 构建.--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/... 路径的来源.) COPYADD 指令是相对于上下文目录的,而不是相对于 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

你会得到你看到的错误.

you'll get the error you see.

如果您不需要引用上下文目录之外的任何内容,则只需更改要传递给 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 ...

这篇关于复制失败:stat/var/lib/docker/tmp/docker-xxx:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆