Docker容器中的HTTP请求因HTTPS端点而失败

时间:2020-05-12 12:45:20

标签: rest docker go https

我已经使用alpine:golang基本映像在golang中构建了一个小应用程序,除其他外,它还使用了来自HTTP.get的响应。

我请求的api端点通过HTTPS(https://jsonplaceholder.typicode.com/users)操作

代码在本地可以正常工作,并且docker镜像可以正常运行,但是在运行时出现以下错误:

The HTTP request failed with error Get "https://jsonplaceholder.typicode.com/users": x509: certificate signed by unknown authority

我不确定这是否是特定的Docker问题(我无法卷曲其他Docker容器的HTTPS),网络的限制(我不在VPN上,但我们确实使用zScaler),或者我是否需要包括/配置某些内容作为我的Dockerfile的一部分。我的dockerfile看起来像:

FROM alpine:golang

#Create and set the working directory
RUN mkdir /app 
WORKDIR /app 

# Copy all the go scripts into the image working directory
COPY /pipelines/core/rtbf-pipeline-1 ./


# Make the binaries executable
RUN chmod +x /app/rtbf-pipeline-1

CMD ["app"]

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:1)

您需要将一组受信任的根证书复制到Docker映像中。

在您的Dockerfile中添加以下内容:

FROM golang:alpine AS build

// build your go app here

FROM scratch

// copy go app from `build`
// ...

//
// add trust certs
//
COPY --from=build etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

答案 1 :(得分:0)

您可能需要添加

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
相关问题