Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker 访问外部 https 的数字证书验证问题 #16

Open
jwchan1996 opened this issue Jul 15, 2020 · 0 comments
Open

docker 访问外部 https 的数字证书验证问题 #16

jwchan1996 opened this issue Jul 15, 2020 · 0 comments

Comments

@jwchan1996
Copy link
Owner

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

我们在构建 docker 镜像时一般使用的是 alpine linux 系统,默认是不带 ca-certificates 根证书的,导致无法识别外部 https 携带的数字证书。

那么,在访问的时候就会抛出 x509: certificate signed by unknown authority 的错误,导致 docker 容器的接口服务返回 500

为了解决证书验证的问题,我们要在构建 docker 镜像的时候把 ca-certificates 根证书给装上,这样就能识别来自外部 https 的数字证书了。

在编辑 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或容器名称'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant