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

问题描述 投票:0回答:2

在我的 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" ]

但是,

docker build . 
Copy . ./
行失败。带有消息
cannot replace to directory /var/lib/docker/overlay2/if2ip5okvavl8u6jpdtpczuog/merged/app/node_modules/@ampproject/remapping with file

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

node.js docker npm windows-subsystem-for-linux aurelia
2个回答
22
投票

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

不太优雅,只需删除项目的

node_modules
目录,然后重新运行
docker build


7
投票

创建文件

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

© www.soinside.com 2019 - 2024. All rights reserved.