更改代码中的任何内容后无法构建 docker

Cannot build docker after I changed anything in the code

提问人:kajahun123 提问时间:11/1/2023 更新时间:11/1/2023 访问量:52

问:

我尝试使用 React 前端和 .Net Core 后端制作一个 Web 应用程序。我试图将它们容器化。
frontend.docker:

FROM node:20.9.0-alpine
COPY frontend /frontend

# build frontend
WORKDIR /frontend
RUN npm ci
RUN npm run build

CMD ["npm", "start"]

后端.docker

#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 5555

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src

COPY ["./RedditAPI/RedditAPI.csproj", "/src"]
RUN dotnet restore "/src/RedditAPI.csproj"
COPY ./RedditAPI .
RUN dotnet build "/src/RedditAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "/src/RedditAPI.csproj" -c Release -o /app/publish/p:UseAppHost=false

FROM base AS final
WORKDIR /app
ENV ASPNETCORE_URLS http://+:5555
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RedditAPI.dll"]

docker-compose的

version: "3.9"
services:
 frontend:
   build:
    context: .
    dockerfile: frontend.dockerfile
  image: frontend:latest
  container_name: frontend
  ports:
    - "3000:3000"
  environment:
    - CHOKIDAR_USEPOLLING=true
backend:
  container_name: backend
  build:
    context: .
    dockerfile: backend.dockerfile
  image: backend:latest
  environment:
    ASPNETCORE_ENVIRONMENT: Development
    ASPNETCORE_URLS: http://+:5555
  ports:
    - "5555:5555"

当我第一次构建它时,它会完美地构建,但是当我更改前端代码中的某些内容时,添加新的 html 标签,任何东西,它都会给我这个:

=> [4/5] RUN npm ci                                                                                                               
14.0s 
=> => # (node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak 
detected. 
11 close listeners added to [TLSSocket]. Use  
=> => # emitter.setMaxListeners() to increase limit                                                                                     
=> => # (node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak 
detected. 
11 close listeners added to [TLSSocket]. Use  
=> => # emitter.setMaxListeners() to increase limit
=> => # (node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak 
detected. 
11 close listeners added to [TLSSocket]. Use  
=> => # emitter.setMaxListeners() to increase limit

我做错了什么?

reactjs asp.net asp.net-web-api docker-compose

评论

1赞 stonith404 11/1/2023
在过去的几个月里,我遇到了同样的错误。我认为这与互联网连接速度慢有关。我通过连接到我的移动热点解决了这个问题。可能是您的互联网连接速度很慢吗?
0赞 kajahun123 11/1/2023
@stonith404也许吧,但为什么只有当我在前端更改某些内容时才会发生这种情况?
1赞 stonith404 11/1/2023
失败的步骤是 。每次在前端更改某些内容时,此步骤都会重新运行。npm ci
0赞 kajahun123 11/1/2023
我能做些什么?我目前买不到更快的互联网
1赞 stonith404 11/1/2023
这可能是 npm 的临时错误,因为即使互联网速度很慢,它过去也对我有用。我不能保证互联网是问题所在,但对我来说确实如此。如果您不能使用移动热点,则可以使用构建 Docker 映像的管道(例如 GitHub Workflows)

答: 暂无答案