Docker 容器中的 HTTP 请求失败,并显示 HTTPS 终结点



我在golang中构建了一个小应用程序,使用alpine: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 的一部分。我的码头工人文件看起来像:

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"]

任何帮助将不胜感激

您需要将一组受信任的根证书复制到 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/

您可能需要添加

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

相关内容

最新更新