'Docker build error duplicates of file paths not supported

This is my Dockerfile codes:

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"]

And I've .dockerignore file contains these :

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

I get this error in (step 8 copy . .)

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

docker error

And one other problem is I must install git so there are two commands : apk update && apk add git

because if I don't in npm installation I get git error Idk why this happens if there is anyway that I be able to remove this command it would be better



Solution 1:[1]

I tried this Dockerfile on my side and it's working correctly: I see that you make unused steps like copy your code from base to builder after to prod , on this case you make a turn around without optimize your image layers . You can Use the below Dockerfile to build you Nuxt image:

# 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" ]

To build use this command:

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

Solution 2:[2]

This error can crop up if you have some docker internal files (namely .wh..wh..opq for my instance, there may be others in your instance) that are copied into your container. The solution here is to just delete them in your source as there's no reason to keep them usually.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rassakra
Solution 2 IAmPattycakes