更新时间:2023-11-20 17:21:46
您需要在容器中安装依赖项,而您的 Dockerfile 中缺少该依赖项.
You need to install the dependencies in the container, which is missing from your Dockerfile.
常见的方法是创建一个已经知道你的应用程序的 Dockerfile,并让它复制你的 package.json
文件并执行 npm install
.
The common way is to create a Dockerfile that is already aware of your application, and make it copy your package.json
file and perform an npm install
.
这允许您的容器在您稍后运行应用程序时找到所有代码依赖项.
This allows your container to find all your code dependencies when you later run your application.
参见此处的示例:https://nodejs.org/en/docs/guides/nodejs-docker-网络应用程序/
示例Dockerfile
:
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
当然,您可能需要调整 COPY
命令的路径.
You may need to adapt paths for the COPY
command, of course.