为Docker镜像加入可信任证书

在使用容器访问一个自签名证书站点的时候碰到如下报错:


为Docker镜像加入可信任证书_第1张图片
image.png
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

解决方法:将该证书加到Docker镜像中,让系统信任这类证书
我使用的是基于alpine的镜像,Dockerfile如下

FROM ruby:2.6.3-alpine3.10

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

RUN mkdir -p /usr/local/share/ca-certificates/
COPY ["SelfSignedRootCA.crt","/usr/local/share/ca-certificates"]

RUN ["/bin/bash","-lc","update-ca-certificates"]

build镜像过程中看到如下提醒,可以忽略

WARNING: ca-certificates.crt does not contain exactly one certificate or CRL: skipping

启动并进入容器内检查cat /etc/ssl/certs/ca-certificates.crt,自签名证书已经被加入ca-certificates.crt文件,系统已信任该证书。

参考:CA certificate on linux

你可能感兴趣的:(为Docker镜像加入可信任证书)