英文:
How to execute npm in a Dockerfile for a dotnet project
问题
docker build .
在查找 npm 时失败。请查看下面的 Dockerfile。
奇怪之处
在2023年7月19日(以及之前的许多日期),docker build .
成功执行。我今天检出了7月19日的 Git 提交。但今天 docker build .
失败了。我在多台计算机上尝试了这个命令,但到处都失败。
问题
这是否是将 node.js 加载到 dotnet 项目中的正确方式?
您能解释一下我如何在 dotnet 构建阶段执行 npm 吗?
Dockerfile
FROM node:latest AS node_base
# npm --version 显示 9.8.0,所以 npm 将在这个阶段执行
RUN npm --version
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY --from=node_base . .
# 我期望 `RUN npm --version` 在这个位置工作。但它无法找到 npm。
# npm 在哪里?
# find 命令显示 npm 在 ./usr/local/bin/npm
RUN find . -name npm
# 以下命令失败。npm:未找到
RUN ./usr/local/bin/npm --version
英文:
Issue
docker build .
fails to find npm. See Dockerfile below.
Strangeness
On 19 July, 2023 (and many dates before then) docker build .
succeeded. I checked out the Git commit from 19 July today. docker build .
fails today. I have tried the command on multiple computers. Fails everywhere.
Questions
Is this the correct way to load node.js into a dotnet project?
Will you explain how I can execute npm from the dotnet build stage?
Dockerfile
FROM node:latest AS node_base
# npm --version shows 9.8.0 so npm will execute in this stage
RUN npm --version
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY --from=node_base . .
# I expect `RUN npm --version` to work at this location. However it fails to find npm.
# Where is npm?
# find command shows npm at ./usr/local/bin/npm
RUN find . -name npm
# The following command fails. npm: not found
RUN ./usr/local/bin/npm --version
答案1
得分: 1
The npm command is looking for node
and it does not find it (ie. its location is not in PATH
).
Why don't you start from one of the image (say aspnet
) and use apt-get
to install the other packages (say node
), you'll get a proper setup with the required environment variables.
英文:
The npm command is looking for node
and it does not find it (ie. its location is not in PATH
).
Why don't you start from one of the image (say aspnet
) and use apt-get
to install the other packages (say node
), you'll get a proper setup with the required environment variables.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论