最近这段时间在折腾asp.net core 发布到容器。中间还是遇到点问题。未来个人还需要解决问题的有
1、发布到容器的程序访问Redis服务器错误,但是发布到IIS是完全正常的
2、Docker 容器IP地址设置
3、访问宿主主键局域网内的数据库服务器
目前3点没有解决。。。。时间有限最近也不需要也就是个人测试使用。。所以把这个过程中一些命令和一旦部分问题记录
首先使用的一些docker 命令:
获取容器IPdocker-machine ip defaultDocker 容器镜像删除1.停止所有的container,这样才能够删除其中的images:docker stop $(docker ps -a -q)如果想要删除所有container的话再加一个指令:docker rm $(docker ps -a -q)2.查看当前有些什么imagesdocker images3.删除images,通过image的id来指定删除谁docker rmi <image id>想要删除untagged images,也就是那些id为<None>的image的话可以用docker rmi $(docker images | grep "^<none>" | awk "{print $3}")要删除全部image的话docker rmi $(docker images -q)查看若有容器docker ps
文件配置 Dockerfile:
//#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.//#For more information, please see https://aka.ms/containercompat//FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 AS base//WORKDIR /app//EXPOSE 80//FROM microsoft/dotnet:2.1-sdk-nanoserver-sac2016 AS build//WORKDIR /src//COPY ["NF.Web/NF.Web.csproj", "NF.Web/"]//COPY ["NF.IBLL/NF.IBLL.csproj", "NF.IBLL/"]//COPY ["NF.Common/NF.Common.csproj", "NF.Common/"]//COPY ["NF.ViewModel/NF.ViewModel.csproj", "NF.ViewModel/"]//COPY ["NF.Model/NF.Model.csproj", "NF.Model/"]//COPY ["NF.BLL/NF.BLL.csproj", "NF.BLL/"]//COPY ["NF.AutoMapper/NF.AutoMapper.csproj", "NF.AutoMapper/"]//COPY ["NF.QuartzNet/NF.QuartzNet.csproj", "NF.QuartzNet/"]//RUN dotnet restore "NF.Web/NF.Web.csproj"//COPY . .//WORKDIR "/src/NF.Web"//RUN dotnet build "NF.Web.csproj" -c Release -o /app//FROM build AS publish//RUN dotnet publish "NF.Web.csproj" -c Release -o /app//FROM base AS final//WORKDIR /app//COPY --from=publish /app .//ENTRYPOINT ["dotnet", "NF.Web.dll"]#以上是VS自动生成的。会出问题。在网上找些简单命令测试如下正确运行#添加基础镜像FROM microsoft/dotnet:2.1-aspnetcore-runtime#容器中系统的工作空间WORKDIR /app#拷贝当前文件夹下的文件到容器中系统的工作空间COPY. /app# 设置Docker容器对外暴露的端口EXPOSE 5000# 设置映射IP。不然默认只有8080可以ENV ASPNETCORE_URLS http://+:5000# 放了这个 ZKWeb.System.Drawing 验证码显示正常RUN apt-get update#容器中使用 ["dotnet","系统启动的dll"] 来运行应用程序#使用ENTRYPOINT ["dotnet","系统启动的dll"]#或使用 CMD ["dotnet","系统启动的dll"]ENTRYPOINT ["dotnet", "NF.Web.dll"]
我所参与网站如下:
http://www.cnblogs.com/stulzq/p/9201830.html
https://www.cnblogs.com/stulzq/p/9059108.html(对验证码显示不正确有很大帮助)
关于发布asp.net core 到 Docker CE 的一些问题及相关资料整理
原文地址:https://www.cnblogs.com/daiyekun-blog/p/10197128.html