O
O
olegkrlvs2021-04-26 17:08:47
.NET
olegkrlvs, 2021-04-26 17:08:47

What is the correct way to create a Docker file in a .net core + react project?

Tell me how to create a docker file for two projects, .net core + react? Separately, for each project, a separate file and then combine via docker-compose or one common file?

Project structure:
TestApp:
- TestApp
- TestApp.Core
- TestApp.Database
- ClientApp

And below current Docker file is shared but it doesn't work correctly:

ARG REPO=mcr.microsoft.com/dotnet/core
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
ENV BuildingDocker true
WORKDIR /src
COPY ["TestApp/TestApp.csproj", "TestApp/"]
COPY ["TestApp.Core/TestApp.Core.csproj", "TestApp.Core/"]
COPY ["TestApp.Database/TestApp.Database.csproj", "TestApp.Database/"]
RUN dotnet restore "TestApp/TestApp.csproj"
COPY . .
WORKDIR "/src/TestApp"
RUN dotnet build "TestApp.csproj" -c Release -o /app/build

FROM node:12-alpine as build-node
WORKDIR ClientApp
COPY ClientApp/package.json .
COPY ClientApp/package-lock.json .
RUN npm install
COPY ClientApp/ .
RUN npm run-script build

FROM build AS publish
RUN dotnet publish "TestApp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY --from=build-node /ClientApp/build ./ClientApp/build
CMD ASPNETCORE_URLS=http://*:$PORT dotnet TestApp.dll


Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-04-27
@vabka

In general, static is usually not included in the container - it can be distributed immediately with nginx.
An example of a Dockerfile for backing is in the documentation .

N
Ne4to, 2021-04-30
@Ne4to

static needs to be copied to wwwroot

COPY --from=build-node /ClientApp/build /app/wwwroot

and add support for static files
public void Configure(IApplicationBuilder app)
{
    app.UseDefaultFiles();
    app.UseStaticFiles();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question