在 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
#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"]
因為 Dokcer COPY 的指令不支援上層目錄 (../),因此我們要從最上層目錄,指定 docker file ,來建立容器
docker build -t shopcart . -f ./Comma.Web/Dockerfile
docker Images
docker run -d --name newwebsite -p 80:80 shopcart
docker logs newwebsite
docker save -o C:\Project\shopcart.tar shopcart