victorantos/AngJobs

[Feature Request] run on Docker/Kubernetes

Closed this issue · 2 comments

It would be awesome to see more dot net projects run on Docker out of the box to make it more widely compatible/homogenised with many CI/CD pipelines and running inside a Kubernetes cluster

https://docs.docker.com/engine/examples/dotnetcore/

Here you go. I'll create a pull request later on but here's the quick fix

Add this to the Dockerfile in the same file as the .csproj

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


########
# 
#  Install Node + Angular
# 
# 
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq build-essential libssl-dev nano nodejs

# npm 
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -

# node
RUN apt install nodejs

# check + set node 10 
RUN node --version
RUN npm -v


# angular 
RUN npm install -g @angular/cli yarn 


########
#
# Compile + Run 
#
# 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", "aspnetapp.dll"]

This can be built and run in Docker or on any computer without needing .net installed by running

docker build -t ang-jobs . 
docker run -p 8080:80 ang-jobs

Open browser to localhost:8080

At the moment this is failing due to angular build error as detailed in this issue #60

Hi - really sorry not sure how I missed your comments...

We might try this instead, considering the changes in the latest code:

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY AngJobs.csproj ./
RUN dotnet restore "./AngJobs.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "AngJobs.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AngJobs.dll"]