From 92e9e66538493e22283934a22bdf1b752b9d9d46 Mon Sep 17 00:00:00 2001 From: xyy <544939200@qq.com> Date: Tue, 3 Mar 2026 16:20:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 30 ++++++++++++++++++++++++++++++ ConsoleApp2.csproj | 16 ++++++++++++++++ ConsoleApp2.slnx | 3 +++ Dockerfile | 28 ++++++++++++++++++++++++++++ Program.cs | 2 ++ Properties/launchSettings.json | 10 ++++++++++ 6 files changed, 89 insertions(+) create mode 100644 .dockerignore create mode 100644 ConsoleApp2.csproj create mode 100644 ConsoleApp2.slnx create mode 100644 Dockerfile create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/ConsoleApp2.csproj b/ConsoleApp2.csproj new file mode 100644 index 0000000..1a81153 --- /dev/null +++ b/ConsoleApp2.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + enable + Linux + . + + + + + + + diff --git a/ConsoleApp2.slnx b/ConsoleApp2.slnx new file mode 100644 index 0000000..f4558f3 --- /dev/null +++ b/ConsoleApp2.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2339118 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器,以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。 + +# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时 +FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base +USER $APP_UID +WORKDIR /app + + +# 此阶段用于生成服务项目 +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["ConsoleApp2.csproj", "."] +RUN dotnet restore "./ConsoleApp2.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "./ConsoleApp2.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# 此阶段用于发布要复制到最终阶段的服务项目 +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./ConsoleApp2.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值) +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "ConsoleApp2.dll"] \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..7d85e14 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "ConsoleApp2": { + "commandName": "Project" + }, + "Container (Dockerfile)": { + "commandName": "Docker" + } + } +} \ No newline at end of file