Mark Ku's Blog

Step 1: Open Visual Studio, right-click the project you want to deploy > Add > Docker Support (this generates a Dockerfile in the project directory)

Visual Studio context menu highlighting Add Docker Support option
Visual Studio context menu highlighting Add Docker Support option

Node.js must be installed during the build stage, otherwise the build will fail

Add the following snippet after the FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build line:

# Install NodeJs
RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y gnupg2 && \
wget -qO- https://deb.nodesource.com/setup_12.x | bash - && \
apt-get install -y build-essential nodejs
# End Install

Final Dockerfile after the changes

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

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

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
# Install NodeJs
RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y gnupg2 && \
wget -qO- https://deb.nodesource.com/setup_12.x | bash - && \
apt-get install -y build-essential nodejs
# End Install
WORKDIR /
COPY ["Comma.Web/Comma.Web.csproj", "Comma.Web/"]
COPY ["Comma.Business/Comma.Business.csproj", "Comma.Business/"]
COPY ["Comma.Libray/Comma.Libray.csproj", "Comma.Libray/"]
COPY ["Comma.Common/Comma.Common.csproj", "Comma.Common/"]
COPY ["Comma.Repository/Comma.Repository.csproj", "Comma.Repository/"]
COPY ["Comma.Model/Comma.Model.csproj", "Comma.Model/"]
COPY ["Comma.Pagination/Comma.Pagination.csproj", "Comma.Pagination/"]
RUN dotnet restore "Comma.Web/Comma.Web.csproj"
COPY . .
WORKDIR "/Comma.Web"
RUN dotnet build "Comma.Web.csproj" -c Release -o /app/build

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

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

Build the Docker image

Because Docker's COPY instruction does not support parent directory paths (../), you need to run the build from the top-level directory and explicitly specify the Dockerfile path:

docker build -t shopcart . -f ./Comma.Web/Dockerfile
PowerShell console output detailing Docker build for a .NET Core app
PowerShell console output detailing Docker build for a .NET Core app

Verify the image

docker Images
Windows PowerShell output of docker images command
Windows PowerShell output of docker images command

Create a container from the image you just built

docker run -d --name newwebsite -p 80:80 shopcart

The site should now be accessible at localhost:80

Multikart e-commerce website on localhost displaying fashion banner
Multikart e-commerce website on localhost displaying fashion banner

If the site doesn't start, use docker logs to inspect errors inside the container

docker logs newwebsite

Export the image

docker save -o C:\Project\shopcart.tar shopcart

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11