Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - cannot copy to non-directory: /var/lib/docker/overlay2/xw77p2bxfkhhnwqs5umpl7cbi/merged/app/.git

I am trying to build a docker image on my windows machine and I keep getting this error:

[+] Building 2.1s (12/15)
 => [internal] load build definition from Dockerfile                                                                                                                                                       0.0s 
 => => transferring dockerfile: 538B                                                                                                                                                                       0.0s 
 => [internal] load .dockerignore                                                                                                                                                                          0.0s 
 => => transferring context: 35B                                                                                                                                                                           0.0s 
 => [internal] load metadata for docker.io/library/node:alpine                                                                                                                                             1.0s 
 => [ 1/11] FROM docker.io/library/node:alpine@sha256:6b56197d33a56cd45d1d1214292b8851fa1b91b2ccc678cee7e5fd4260bd8fae                                                                                     0.0s 
 => [internal] load build context                                                                                                                                                                          1.0s 
 => => transferring context: 15.72kB                                                                                                                                                                       1.0s 
 => CACHED [ 2/11] WORKDIR /app                                                                                                                                                                            0.0s 
 => CACHED [ 3/11] COPY package.json .                                                                                                                                                                     0.0s 
 => CACHED [ 4/11] COPY tsconfig.json .                                                                                                                                                                    0.0s 
 => CACHED [ 5/11] COPY swagger.yaml .                                                                                                                                                                     0.0s 
 => CACHED [ 6/11] COPY services .                                                                                                                                                                         0.0s 
 => CACHED [ 7/11] RUN yarn install                                                                                                                                                                        0.0s 
 => ERROR [ 8/11] ADD . /app                                                                                                                                                                               0.0s 
------
 > [ 8/11] ADD . /app:
------
cannot copy to non-directory: /var/lib/docker/overlay2/xw77p2bxfkhhnwqs5umpl7cbi/merged/app/.git

My Dockerfile is the following:

FROM node:alpine

#Create Directory for the Container
WORKDIR /app

#Copy the package.json and tsconfig.json to work directory
COPY package.json .
COPY tsconfig.json .
COPY swagger.yaml .
COPY services . 

#Install all packages
RUN yarn install

#Copy all other source code to work directory
ADD . /app

#Build sources
RUN yarn run build

#Clean src directory
RUN rm -rf ./src/
RUN rm -rf ./services/src/

#Expose Ports
EXPOSE 3000

#Entry
CMD ["yarn", "start"]

This Dockerfile works on my colleagues' Linux machines but fails on my windows machine.

This is my Docker version

Docker version 20.10.7, build f0df350

Running on windows and using the wsl 2 to interact with it.

But the build also fails using the Windows command prompt.

Thank you in advance for the help!

like image 292
Pedro Dimas Avatar asked Sep 14 '25 00:09

Pedro Dimas


2 Answers

Just verify the .git is actually a file or folder. Or check for any name conflict between a folder and file.

Seems like you are trying to copy a folder to a file(non-directory).

I have faced a similar issue error: failed to solve: cannot replace to directory /var/lib/docker/overlay2/*/*/folder_a with file. Turns out i have a binary file with a name 'folder_a'.

Deleting the file which matches the folder_name solved the issue for me.

like image 131
Vaisakh Rajagopal Avatar answered Sep 15 '25 14:09

Vaisakh Rajagopal


My case Destination directory not created before copy command

RUN mkdir <destination directory>
like image 29
Radhakrishnan Avatar answered Sep 15 '25 12:09

Radhakrishnan