代码之家  ›  专栏  ›  技术社区  ›  david benalal

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

  •  0
  • david benalal  · 技术社区  · 7 年前

    当我不使用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 回复  |  直到 7 年前
        1
  •  2
  •   david benalal    7 年前

    移除

    environment: - ASPNETCORE_ENVIRONMENT=Development 
    

    从作曲开始。覆盖文件修复了所有这些问题。我不知道为什么会有问题。

        2
  •  1
  •   Pepito Stornudo    7 年前

    你的文件在吗 ./ ./app ? 如果在 ./ 更改docker compose。yml to build: ./

    编辑

    我刚刚意识到,您正在指定两者 image build 在你的码头上。yml;除掉 形象 .