首先记录一个问题,今天在用 Jenkins 构建项目的时候忽然出现包源的错误:git
/usr/share/dotnet/sdk/2.2.104/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/....csproj]
/usr/share/dotnet/sdk/2.2.104/NuGet.targets(114,5): error : The HTTP request to 'GET https://api.nuget.org/v3/index.json' has timed out after 100000ms. [/....csproj]
复制代码
nuget的包源没法访问(没法ping通),而我在一台服务器上访问https://api.nuget.org/v3/index.json
时则会自动重定向到https://nuget.cdn.azure.cn/v3/index.json
。github
可是打包机器执行dotnet restore
却仍是没法还原成功,即便指定包源后即dotnet restore -s https://nuget.cdn.azure.cn/v3/index.json
能还原一部分包,部分包依旧没法还原docker
最后测试发现,包源只是部分地区没法访问,能够尝试切换源/使用Nuget.Config文件试试,固然最快的仍是经过科学的方式访问~。json
若本地 VS 的包管理器也没法正常使用,切换源(nuget.cdn.azure.cn/v3/index.js…)便可 api
而后这篇文章实际上是另外的一个问题,以前我构建了一个基础镜像包,基于FROM microsoft/dotnet:2.2-aspnetcore-runtime
构建,而我构建时使用的sdk镜像是FROM microsoft/dotnet:2.2-sdk
bash
9.23号(.net core 3.0发布)以前还可以正常构建,今天在解决了上面包源问题后,镜像构建成功并发布到服务器,却发现镜像没法启动起来。服务器
报错信息以下并发
The specified framework 'Microsoft.NETCore.App', version '2.2.2' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
- The following versions are installed:
2.2.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
复制代码
既然说是版本问题,那就尝试着将基础进行修改成FROM microsoft/dotnet:2.2.2-aspnetcore-runtime
,果真,从新构建后可以好好的运行起来了。app
那么我是如何构建的基础镜像的,只需下面 3 个文件就搞定了。测试
阿里云的软件包源,可用于一些基础镜像中没有的软件安装,写入到 sources.list 供后面使用
deb http://mirrors.aliyun.com/debian jessie main contrib non-free
deb-src http://mirrors.aliyun.com/debian jessie main contrib non-free
deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian jessie-updates main contrib non-free
deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free
复制代码
基于dotnet:2.2.2 aspnetcore-runtime
,并在其中安装 libgdiplus
,设置时区,具体的能够根据本身的项目须要去构建
文件:Dockerfile
FROM microsoft/dotnet:2.2.2-aspnetcore-runtime
WORKDIR /app
COPY sources.list /app/sources.list
RUN rm -f /etc/apt/sources.list && mv sources.list /etc/apt/ && apt-get update -y && apt-get install -y libgdiplus && apt-get clean && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
# 时区设置
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# ENTRYPOINT ["./xxxxx.dll"]
复制代码
要推送镜像到阿里云,须要先去阿里云开通并建立命名空间 须要先登陆云端镜像仓库 ,登陆阿里云以下
文件名:build.sh (Linux添加执行权限 chmod +x ./build.sh
)
export ALIYUN_DOCKER_CLOUD_URL=registry.cn-hangzhou.aliyuncs.com
export DOCKER_IMAGE_NAME=yimocoding/dotnet2.2.2-base
export BUILD_NUMBER=latest
docker build -t $DOCKER_IMAGE_NAME -f ./Dockerfile .
docker tag $DOCKER_IMAGE_NAME $ALIYUN_DOCKER_CLOUD_URL/$DOCKER_IMAGE_NAME:$BUILD_NUMBER
echo 推送镜像到云端
docker push $ALIYUN_DOCKER_CLOUD_URL/$DOCKER_IMAGE_NAME:$BUILD_NUMBER
echo '删除本地镜像'
docker rmi $DOCKER_IMAGE_NAME
docker rmi $ALIYUN_DOCKER_CLOUD_URL/$DOCKER_IMAGE_NAME:$BUILD_NUMBER
复制代码
文件建立完成后,执行 build.sh
便可构建镜像并推送到阿里云的镜像仓库,若想提交到其余云仓库,修改脚本中的变量便可
真是,人在家中坐,锅从天落,而为了更好的接锅,记录一二,省得到时候望码兴叹。