In this tutorial, we will be deploying the JSViewer_MVC_Core sample using Docker on Windows environment. Download the JSViewer_MVC_Core sample from our WebSamples18 GitHub repository.
To create a docker file, follow the steps as described below:
Copy Code
|
|
---|---|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# installing node
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \
&& apt update \
&& apt install -y nodejs
|
Copy Code
|
|
---|---|
WORKDIR /src COPY . . ENV PATH="$PATH:/root/.dotnet/tools" RUN dotnet restore "./JSViewer_MVC_Core.csproj" RUN dotnet build "JSViewer_MVC_Core.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "JSViewer_MVC_Core.csproj" -c Release -o /app/publish |
Copy Code
|
|
---|---|
WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "JSViewer_MVC_Core.dll"] |
Therefore, we now have a docker file with the following commands.
Copy Code
|
|
---|---|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build # installing node RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \ && apt update \ && apt install -y nodejs WORKDIR /src COPY . . ENV PATH="$PATH:/root/.dotnet/tools" RUN dotnet restore "./JSViewer_MVC_Core.csproj" RUN dotnet build "JSViewer_MVC_Core.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "JSViewer_MVC_Core.csproj" -c Release -o /app/publish # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal RUN apt-get update; \ ENV ASPNETCORE_URLS="http://+:5000" WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "JSViewer_MVC_Core.dll"] |
Open the command prompt and build an image named 'viewerapp' from the above-created docker file and use the docker build command as follows.
Copy Code
|
|
---|---|
docker build --pull -t viewerapp |
The console screenshot on executing the above command is shown.
For more information on the above command, please refer to the link: https://docs.docker.com/reference/cli/docker/buildx/build/.
We will use the following docker run command and would bind the port 8090 of the host system to the container’s 5000 port where the above specified JSViewer application is running.
Copy Code
|
|
---|---|
docker run -dp 8090:5000 viewerapp |
The console screenshot on executing the above command is shown.
For more information on the above command, please refer to the link: https://docs.docker.com/reference/cli/docker/container/run/
Now, try opening the localhost:8090 in the browser of the host system, the output should be as follows.
You can activate the license with Pipeline License or with Standard Developer License as explained in the Licensing Build Agents/Pipelines using Command Line page.