【问题标题】:Docker build error duplicates of file paths not supported不支持 Docker 构建错误的文件路径重复
【发布时间】:2022-05-10 01:58:24
【问题描述】:

这是我的 Dockerfile 代码:

FROM node:16.10-alpine3.12 as base
RUN apk update
RUN apk add git
WORKDIR /app
COPY package.json .

FROM base as builder
RUN npm i
COPY . .
RUN npm run build

FROM base as prod
WORKDIR /exfront
COPY --from=builder /app/package.json .
RUN npm i
COPY --from=builder /app/.nuxt .nuxt
COPY --from=builder /app/static static
COPY --from=builder /app/nuxt.config.js .
EXPOSE 3500
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3500
CMD ["npm","start"]

我的 .dockerignore 文件包含这些:

.dockerignore
node_modules
npm-debug.*
Dockerfile
.git
.gitignore

我在(第 8 步复制......)中收到此错误

Error processing tar file(duplicates of file paths not supported):

另一个问题是我必须安装 git,所以有两个命令: apk 更新 && apk 添加 git

因为如果我不在 npm 安装中我得到 git 错误 Idk 为什么会发生这种情况,如果无论如何我能够删除此命令会更好

【问题讨论】:

    标签: docker vue.js dockerfile nuxt.js dockerignore


    【解决方案1】:

    我尝试了这个 Dockerfile,它工作正常: 我看到您执行了未使用的步骤,例如将代码从基础复制到构建器,然后再到产品,在这种情况下,您在没有优化图像层的情况下转身。 你可以使用下面的 Dockerfile 来构建你的 Nuxt 镜像:

    # Dockerfile
    FROM node:16.10-alpine3.12 as base
    
    # create destination directory
    RUN mkdir -p /usr/src/nuxt-app
    WORKDIR /usr/src/nuxt-app
    
    # update and install dependency
    RUN apk update && apk upgrade
    RUN apk add git
    
    # copy the app, note .dockerignore
    COPY . /usr/src/nuxt-app/
    RUN npm install
    RUN npm run build
    
    
    ENV NUXT_HOST=0.0.0.0
    ENV NUXT_PORT=3000
    EXPOSE 3000
    
    CMD [ "npm", "start" ]
    

    要构建使用这个命令:

    docker build -t nuxt-app:v0.1 .
    

    【讨论】:

    • 我想将开发文件放在一个容器中并在另一个容器中构建文件,因此我有多个步骤,并且在我的朋友系统副本中进行了测试。 .命令工作正常,但在我的系统中我得到了重复的错误
    • 从一个 Dockerfile 你可以创建一个镜像,从一个镜像你可以创建一个或多个容器。
    【解决方案2】:

    如果您有一些复制到容器中的 docker 内部文件(在我的实例中为 .wh..wh..opq,您的实例中可能还有其他文件),则可能会出现此错误。这里的解决方案是在您的源中删除它们,因为通常没有理由保留它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      • 2020-05-27
      • 1970-01-01
      • 2014-07-07
      相关资源
      最近更新 更多