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