我正在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
目录复制到镜像中。这个错误本身很不寻常,但这样做会覆盖之前的RUN docker install
步骤的结果,并且如果主机和容器是不同的操作系统,则可能会导致问题。您是否有一个.dockerignore
文件来排除node_modules
树? - David Maze