ubuntu Docker 镜像go使用https出现X509: Certificate Signed by Unknown Authority
问题成因:应用镜像时,如果没有向镜像中添加证书颁发机构(CA, Certificate Authority)发布的证书,您就有可能遭遇这个错误。解决方法1:可以添加ca-certificates证书,可以将CA证书打包到docker镜像,Dockerfile中增加。解决方法2:忽略证书校验,不过有些第三方库没有这个提供的时候只能使用方法1了。
·
1、问题成因:
应用镜像时,如果没有向镜像中添加证书颁发机构(CA, Certificate Authority)发布的证书,您就有可能遭遇这个错误。
2、解决方法
解决方法1:可以添加ca-certificates证书,可以将CA证书打包到docker镜像,Dockerfile中增加
run apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends ca-certificates curl
解决方法2:忽略证书校验,不过有些第三方库没有这个提供的时候只能使用方法1了
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
resp, err := client.Get("https://localhost:8081")
if err != nil {
fmt.Println("error:", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
更多推荐
已为社区贡献1条内容
所有评论(0)