I am taking baby steps in Docker. It will be good for me if anyone describe me the steps for deploying code on docker. My frontend application is in ReactJS and backend application is in .net core. I want to create Image file for it.
1 Answer
Both Docker and Microsoft has some guides on building and hosting ASP.NET Core in docker which is the first step you need to do:
Dockerize an ASP.NET Core application
Docker images for ASP.NET Core
If you want to include your ReactJS client in the image and use ASP.NET Core to host it:
- Build your ReactJS client
- Include it in the docker image by copying the client files to the wwwroot of you ASP.NET Core application either before building the server or as a part of the docker build process.
Here's how it looks for one of my project, you may be able to modify it for your needs:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS restore
WORKDIR /src
RUN dotnet restore "YourProject.Web/YourProject.Web.csproj"
FROM restore as build
COPY . .
WORKDIR "/src/YourProject.Web"
RUN dotnet build "YourProject.Web.csproj" -c Debug --no-restore -o /app
FROM build AS publish
RUN dotnet publish "YourProject.Web.csproj" -c Debug --no-restore -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
COPY ./ReactClientFiles ./wwwroot
ENTRYPOINT ["dotnet", "YourProject.Web.dll"]
Make sure ASP.NET Core is setup to host static files.