Loading

docker访问外部https数字证书问题

一般我们构建的 docker 镜像使用的都是 alpine linux 系统,默认是不带 ca-certificates 根证书的,导致无法识别外部 https 携带的数字证书。
在访问的时候,会抛出509:certificate signed by unknown authority错误,导致 docker 容器的接口服务返回报错。

为了解决证书验证的问题,我们需要在构建 docker 镜像的时候将 ca-certificates 根证书装上。
在 Dockerfile 中加入如下内容:

RUN apk --no-cache add ca-certificates \
  && update-ca-certificates

对于已经构建好的镜像,如果我们想手动安装的话,可以使用如下方法。

# 进入容器
docker exec -it '容器ID或容器名称' bash
# 安装根证书
apk --no-cache add ca-certificates && update-ca-certificates
# 若出现类似如下的警告,忽略
WARNING: ca-certificates.crt does not contain exactly one certificate or CRL: skipping
# 重启容器
docker restart '容器ID或容器名称'

更多技术文章,请关注我的个人博客 www.immaxfang.com 和小公众号 Max的学习札记

posted @ 2022-09-05 01:07  immaxfang  阅读(454)  评论(0编辑  收藏  举报