一、运行问题
①、未正常运行
1、错误信息(附截图):Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2、处理及解决
#检查docker是否正常启动
[root@k8s-node-2 ~]# systemctl status docker
#重启docker服务
[root@k8s-node-2 ~]# systemctl restart docker
/******检查docker配置*********/
#docker 配置【registry-mirrors:阿里云镜像】
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
}
②、找不到 .dockerignore文件
1、错误信息(附截图):COPY failed: file not found in build context or excluded by .dockerignore: stat Apricot.AspNetcore.WebApi\Apricot.AspNetcore.WebApi.csproj: file does not exist
2、处理及解决
#转到上级目录
E:\RCP\Apricot.AspNetcore.WebApi\Apricot.AspNetcore.WebApi> cd ..
#构建镜像
E:\RCP\Apricot.AspNetcore.WebApi> docker build -f E:\RCP\Apricot.AspNetcore.WebApi\Apricot.AspNetcore.WebApi\Dockerfile -t apricot .
3、项目具体结构
4、执行结果
③、加载nuget.json失败
1、错误信息(附截图):error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json. [C:\src\Apricot.AspNetcore.WebApi\Apricot.AspNetcore.WebApi.csproj]
2、处理及解决
#查看docker 网络列表
E:\RCP\Apricot.AspNetcore.WebApi> docker network ls
NETWORK ID NAME DRIVER SCOPE
aa43c872c08c Default Switch ics local
cf462af8c990 Hypev-Network transparent local
82c2043158dc nat nat local
916fac8a16cc none null local
======================================
连接本机真实网卡:Default Switch【具体查看hype-v对应的网卡】
======================================
#使用真实网卡网络构建
E:\RCP\Apricot.AspNetcore.WebApi> docker build -f E:\RCP\Apricot.AspNetcore.WebApi\Apricot.AspNetcore.WebApi\Dockerfile -t apricot . --network=Hypev-Network
3、构建截图
④、nexus私有包
1、错误信息(附截图):
C:\src\Sq.Authorize.Center\Sq.Authorize.Center.csproj : error NU1101: Unable to find package Sqray.Net. No packages exist with this id in source(s): nuget.org
Failed to restore C:\src\Sq.Authorize.Center\Sq.Authorize.Center.csproj (in 10.37 sec).
2、处理及解决
#.dockerignore 同级目录添加nuget.config【添加nexus配置,官网】
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="public" value="https://nuget.cdn.azure.cn/v3/index.json" />
<add key="nexus" value="http://xxx.xxx.xxx.xxx:8500/repository/nuget-group/"/>
</packageSources>
<packageSourceCredentials>
<customfeed>
<add key="Username" value="account" />
<add key="ClearTextPassword" value="password" />
</customfeed>
</packageSourceCredentials>
</configuration>
#Dockerfile 添加拷贝命令
COPY ./nuget.config .
3、nuget.config 目录结构
4、Dockerfile 拷贝命令
5、提示不是https访问【忽略不影响】
⑤、镜像OS(操作系统)
1、Linux版本、Windows版本:只能在对应操作系统构建对应镜像,windows系统构建默认拉取win运行时(Runtime.win-x64.6.0.13)。
2、Linux环境拉取windows镜像(附截图)【生成不同环境镜像即可】:image operating system "windows" cannot be used on this platform。
⑥、切换harbor【私有仓库】
1、错误信息(附截图):Login did not succeed, error: Error response from daemon: Get "https://192.168.10.235:80/v2/": http: server gave HTTP response to HTTPS client
2、处理及解决
#编辑docker配置
[root@k8s-node-2 ~]# vi /etc/docker/daemon.json
#添加insecure-registries节点【对应harbor地址】
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"],
"insecure-registries":["192.168.10.235:80"]
}
#重启docker
[root@k8s-node-2 ~]# systemctl restart docker
#重新登录
[root@k8s-node-2 ~]# docker login 192.168.10.235:80
#打镜像标签【192.168.10.235:80/tmp -> 对应harbor仓库地址】
[root@k8s-node-2 ~]# docker tag mark 192.168.10.235:80/tmp/mark
#推送镜像至harbor
[root@k8s-node-2 ~]# docker push 192.168.10.235:80/tmp/mark
3、推送结果
二、构建问题
①、构建缓存
1、构建缓存:构建过程中失败或暂停缓存,删除缓存可构建新镜像。