无法使用文件替换目录 /var/lib/docker/overlay2/if2ip5okvavl8u6jpdtpczuog/merged/app/node_modules/@ampproject/remapping

Jac*_*ult 6 node.js npm docker aurelia windows-subsystem-for-linux

在我的 Windows 计算机上,我尝试使用以下 Dockerfile 构建容器化的 Node.js 应用程序:

  # use latest version of nodejs
  FROM node:lts-alpine
  
  # install aurelia-cli to build the app & http-server to serve static contents
  RUN npm i -g http-server
  RUN npm i -g aurelia-cli
  
  # set working directory to app
  # henceforth all commands will run inside this folder
  WORKDIR /app
  
  # copy package.json related files first and install all required dependencies
  COPY package*.json ./
  RUN npm install
  
  # copy the rest of the files and folders & install dependencies
  COPY . ./
  RUN npm run build
  
  # by default http-server will serve contents on port 8080
  # so we expose this port to host machine
  EXPOSE 8080
  
  CMD [ "http-server" , "dist" ]
Run Code Online (Sandbox Code Playgroud)

然而,docker build . 失败了Copy . ./。与消息cannot replace to directory /var/lib/docker/overlay2/if2ip5okvavl8u6jpdtpczuog/merged/app/node_modules/@ampproject/remapping with file

我需要做什么才能构建容器映像?

Jac*_*ult 19

添加node_modules.dockerignore与 Dockerfile 位于同一目录中的文件,如下所述 (h/t David Maze )。

不太优雅的是,只需删除项目的node_modules目录然后重新运行即可docker build


小智 5

创建文件.dockerignore并添加node_modules/并尝试再次构建,这应该可以解决您面临的错误。