运行netcore-react应用时出现docker-compose错误

时间:2018-10-04 13:36:29

标签: docker asp.net-core docker-compose

当我不使用docker-compose构建我的应用程序时:

docker build -t aspnetapp .
docker run -d -p 8080:80 --name myapp aspnetapp

docker容器运行正常。但是,当我尝试使用docker-compose up运行它时,图像可以成功构建,但是网站在加载时给我错误。

dockerfile:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "app.dll"]

docker-compose:

version: '3.4'

  services:
    app:
      image: aspnetapp     
      build: ./app
      ports:
        - "8080:80"
AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.

[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Make sure the executable is in one of those directories, or update your PATH.

2 个答案:

答案 0 :(得分:1)

您的Dockerfile是在0.04183992052616166 还是./中?如果在./app中,请将docker-compose.yml更改为./

编辑

我刚刚意识到您在docker-compose.yml中同时指定了build: ./image;摆脱build

答案 1 :(得分:0)

删除

environment: - ASPNETCORE_ENVIRONMENT=Development 
从compose.override文件中的

修复了所有这些问题。我不知道为什么会这样。