docker 构建编排过程中常见问题

docker 构建过程中常见问题

Docker 构建的问题指南

(一)docker镜像构建

问题1:解决 Docker 构建中的网络连接问题

Docker 构建过程中可能因网络配置或代理问题导致连接失败。以下是常见问题及解决方法:

1、检查基础网络连通性

确认宿主机可以正常访问互联网,执行 ping 8.8.8.8curl -v https://www.google.com 测试基础网络。若宿主机无法联网,需先解决主机网络问题。

2、配置 Docker Daemon 代理

若企业网络需通过代理访问外网,需在 Docker 服务配置中添加代理设置:

  1. 创建或编辑 /etc/systemd/system/docker.service.d/http-proxy.conf
  2. 添加以下内容:
ini 复制代码
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080"
Environment="HTTPS_PROXY=http://proxy.example.com:8080"
Environment="NO_PROXY=localhost,127.0.0.1,.internal"
  1. 重载配置并重启服务:
bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker
3、使用国内镜像加速

国内用户可配置 Docker 镜像加速器提升下载速度:

  1. 编辑 /etc/docker/daemon.json
  2. 添加镜像源(如阿里云):
json 复制代码
{
  "registry-mirrors": ["https://<your-aliyun-mirror>.mirror.aliyuncs.com"]
}
4、构建时指定 DNS

当默认 DNS 解析失败时,可通过 --dns 参数指定:

bash 复制代码
docker build --dns 8.8.8.8 -t myimage .

或在 Dockerfile 中临时覆盖 DNS:

dockerfile 复制代码
RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf && \
    apt-get update
5、处理容器内证书问题

若遇到 SSL 证书验证失败,可临时禁用验证(不推荐生产环境):

dockerfile 复制代码
RUN echo "Acquire::https::Verify-Peer \"false\";" > /etc/apt/apt.conf.d/99verify-peer.conf

或正确安装 CA 证书:

dockerfile 复制代码
COPY ./company-ca.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates
6、调整 MTU 值

在某些网络环境下需调整 MTU 避免分包问题:

bash 复制代码
docker daemon --mtu 1450

或通过 /etc/docker/daemon.json 配置:

json 复制代码
{
  "mtu": 1450
}

问题2: Docker 镜像构建无法连接github

1、问题分析:

尽管我们尝试了 GitHub 代理服务,但仍然遇到了网络连接问题,这表明直接通过 git clone 方式在 Docker 构建过程中获取 face_recognition_models 仓库存在困难。

2、解决方案:

为了避免网络问题,我修改了 Dockerfile,改用 wget 下载仓库的 ZIP 包,然后解压并安装。这种方式通常比 git clone 更稳定,尤其是在网络条件不佳的情况下。同时我也添加了 wget 和 unzip 工具的安装,确保这些工具在容器中可用。

原始内容:

shell 复制代码
# 克隆并安装face_recognition_models
RUN git clone https://github.com/ageitgey/face_recognition_models && \
    cd face_recognition_models && \
    pip install -e .

修改后的内容:

shell 复制代码
# 下载并安装face_recognition_models
RUN apt-get update && apt-get install -y wget unzip && \
    wget https://github.com/ageitgey/face_recognition_models/archive/master.zip && \
    unzip master.zip && \
    cd face_recognition_models-master && \
    pip install -e .

(二)docker-compose 容器编排

相关推荐
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS2 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
AI职业加油站2 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
此冬歌咏2 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
玉&心2 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing2 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
-梅2 天前
linux(8) 软硬链接
linux·运维·服务器
赵文宇(温玉)2 天前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang2 天前
上传本地镜像到harbor中
docker·容器·持续部署
张洛闻Eren2 天前
k8s云原生【第十课】:水平 Pod 自动扩缩容
运维·数据库·云原生·kubernetes·github