在我的 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_modules
添加到与 Dockerfile 相同目录中的 .dockerignore
文件中,如 here 所述: (h/t David Maze ).
不太优雅,只需删除项目的 node_modules
目录,然后重新运行 docker build
。
关于node.js - 无法替换到目录/var/lib/docker/overlay2/if2ip5okvavl8u6jpdtpczuog/merged/app/node_modules/@ampproject/remapping with file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72955265/