• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

docker容器中部署Go服务时,请求https文件时抛错

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

错误提示:

Get https://res.ddkt365.com/ddktRes/imageRes/wx_headimg/0f1d9e55913c22bcaf7cca9b38048d29.jpeg: x509: certificate signed by unknown authority -> http.Get
panic: runtime error: invalid memory address or nil pointer dereference

 

 

 

是 CA 证书的问题,解决方案就是 拷贝 alpine 镜像中的证书

 

附上 dockerfile 代码

# 基础镜像是 docker 仓库的 busybox
FROM alpine as certs
RUN apk update && apk add ca-certificates
# 从别的镜像中 copy 证书
FROM busybox
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
# 作者签名
LABEL author="[email protected]"
# 工作目录
WORKDIR /root

# 添加文件
ADD ./bin/ddkt-poster-go ./ddkt-poster-go
ADD ./bin/conf.toml ./conf.toml
ADD ./fonts ./fonts
# 暴露出端口号
#EXPOSE 8080
# 运行容器执行时的口令
ENTRYPOINT ["./ddkt-poster-go", "-conf", "conf.toml"]

  

 

 

 

liugx@MacBook-Pro  ~/work/personal/golang/ddkt-poster   liugx_code_youhua ●  docker build -t ddkt-poster-go .
Sending build context to Docker daemon  78.08MB
Step 1/10 : FROM alpine as certs
latest: Pulling from library/alpine
aad63a933944: Pull complete 
Digest: sha256:b276d875eeed9c7d3f1cfa7edb06b22ed22b14219a7d67c52c56612330348239
Status: Downloaded newer image for alpine:latest
 ---> a187dde48cd2
Step 2/10 : RUN apk update && apk add ca-certificates
 ---> Running in 1a290f0b3176
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
v3.11.5-5-gfa48ebadee [http://dl-cdn.alpinelinux.org/alpine/v3.11/main]
v3.11.5-1-ge59ae1cbad [http://dl-cdn.alpinelinux.org/alpine/v3.11/community]
OK: 11265 distinct packages available
(1/1) Installing ca-certificates (20191127-r1)
Executing busybox-1.31.1-r9.trigger
Executing ca-certificates-20191127-r1.trigger
OK: 6 MiB in 15 packages
Removing intermediate container 1a290f0b3176
 ---> 409d89df1e27
Step 3/10 : FROM busybox
 ---> 83aa35aa1c79
Step 4/10 : COPY --from=certs /etc/ssl/certs /etc/ssl/certs
 ---> f3d288b6f60c
Step 5/10 : LABEL author="[email protected]"
 ---> Running in 81fa23a198e9
Removing intermediate container 81fa23a198e9
 ---> 474ca6db3d19
Step 6/10 : WORKDIR /root
 ---> Running in 670487d3f2a5
Removing intermediate container 670487d3f2a5
 ---> ebbc723821b0
Step 7/10 : ADD ./bin/ddkt-poster-go ./ddkt-poster-go
 ---> 89d7a0e23eca
Step 8/10 : ADD ./bin/conf.toml ./conf.toml
 ---> 4ba50a3e49f8
Step 9/10 : ADD ./fonts ./fonts
 ---> 672cb62f608a
Step 10/10 : ENTRYPOINT ["./ddkt-poster-go", "-conf", "conf.toml"]
 ---> Running in 86afb270dab0
Removing intermediate container 86afb270dab0
 ---> da2ec7a93580
Successfully built da2ec7a93580
Successfully tagged ddkt-poster-go:latest
 liugx@MacBook-Pro  ~/work/personal/golang/ddkt-poster   liugx_code_youhua ●  
执行过程

 

引用链接:

https://stackoverflow.com/questions/45388934/how-do-i-make-an-https-call-in-a-busybox-docker-container-running-go

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap