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

Mol*_*pad 1 rest https go docker

我在 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
Run Code Online (Sandbox Code Playgroud)

我不确定这是否是一个特定的 Docker 问题(我无法从其他 docker 容器卷取 HTTPS)、我的网络限制(我没有使用 VPN,但我们确实使用 zScaler),或者我是否需要包含/configure 一些东西作为我的 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"]
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

col*_*tor 5

您需要将一组受信任的根证书复制到您的 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 Code Online (Sandbox Code Playgroud)