docker命令:https://www.runoob.com/docker/docker-build-command.html
1、新建 .net core api 选择docker支持 ,选择对应目标系统,会自动生成一个dockerfile文件,修改文件内容(因为尝试build 默认的文件会报一些路径错误,索性改掉了)
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY Emo.Api.csproj . RUN dotnet restore "Emo.Api.csproj" COPY . . WORKDIR /src RUN dotnet build "Emo.Api.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "Emo.Api.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "Emo.Api.dll"]
2、打包镜像(“.” 这里的点要注意),打包后可以通过 docker images 查看
docker build -t emoapi:v1 .
3、运行镜像
docker run -d -p 8700:80 --name emoapitest1 emoapi
4、运行后访问