gpt4 book ai didi

docker - 在 docker 中附加卷后找不到模块

转载 作者:行者123 更新时间:2023-12-04 14:49:31 26 4
gpt4 key购买 nike

这是我的dockerfile

FROM node:15
# sets the folder structure to /app directory
WORKDIR /app
# copy package.json to /app folder
COPY package.json .
RUN npm install
# Copy all files from current directory to current directory in docker(app)
COPY . ./
EXPOSE 3000
CMD ["node","index.js"]

我在我的 powershell 中使用这个命令在容器中运行图像

docker run -v ${pwd}:/app -p 3000:3000 -d --name node-app node-app-image

${pwd}returns the current directory.But as soon as I hit enter, somehow node_modules isn't being installed in the container and I get "express not found" error in the log.[![Docker log][1]][1]I can't verify if node_modules isn't being installed because I can't get the container up to run the exec --it command.


I was following a freecodecamp tutorial and it seems to work in his pc and I've tried this command in command prompt too by replacing ${pwd} by %cd%.


在我在命令中添加卷标志之前,这曾经工作正常。[1]: /image/4Fifu.png

最佳答案

您的问题是您在某处构建您的图像,然后尝试将另一个文件夹映射到它。

|_MyFolder/
|_ all-required-files
|_ all-required-folders
|_ Dockerfile

docker build -t node-app-image .

docker run -p 3000:3000 -d --name node-app node-app-image

简化的 Dockerfile

FROM node:15
# sets the folder structure to /app directory
WORKDIR /app

# Copy all files from current directory to current directory in docker(app)
COPY . ./

RUN npm install

EXPOSE 3000
CMD ["node","index.js"]

关于docker - 在 docker 中附加卷后找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69287993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com