我正在尝试从 Docker 容器连接到在 Go 中创建的 HTTPS 会话,当我在本地运行它时它工作正常,但是一旦我尝试在容器中运行它,我就无法访问 URL。func main() { // I'm using Go-Chi V5 r := chi.NewRouter() // TLS connection. Inspired from https://blog.cloudflare.com/exposing-go-on-the-internet tlsConfig := &tls.Config{ PreferServerCipherSuites: true, CurvePreferences: []tls.CurveID{ tls.CurveP256, tls.X25519, }, MinVersion: tls.VersionTLS12, CipherSuites: []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, }, } srv := &http.Server{ Addr: "localhost:9090", ReadTimeout: 5 * time.Second, WriteTimeout: 20 * time.Second, IdleTimeout: 200 * time.Second, TLSConfig: tlsConfig, Handler: r, } r.Get("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hello world")) }) err := srv.ListenAndServeTLS("./.dev/localhost.crt", "./.dev/localhost.key") if err != nil { log.Fatalf("server failed to start: %v", err) }}我的 Dockerfile:FROM golang:1.17-buster AS buildWORKDIR /appCOPY go.mod .COPY go.sum .RUN go mod downloadCOPY ./.dev/localhost.key .COPY ./.dev/localhost.crt .COPY . .RUN go build -o /dev-admin ./cmd/admin#### Deploy##FROM gcr.io/distroless/base-debian10WORKDIR /COPY --from=build /dev-admin /dev-adminCOPY --from=build ./app/localhost.key ./.dev/localhost.keyCOPY --from=build ./app/localhost.crt ./.dev/localhost.crtEXPOSE 9090EXPOSE 443ENTRYPOINT ["/dev-admin"]$ 卷曲 https://localhost:9090curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to localhost:9090当我尝试正常的 HTTP 版本时,容器工作正常,所以只有 HTTPS 被阻塞,我不知道它是什么。
2 回答
慕村9548890
TA贡献1884条经验 获得超4个赞
问题似乎出在您的 docker-compose.yaml 中。您只转发端口 9090。虽然 SSL 需要 443。
像这样,它应该工作:
version: '3.9'
services:
web:
image: api_test
build: .
ports:
- '9090:9090'
- '443:443'
volumes:
- .:/app
- 2 回答
- 0 关注
- 142 浏览
添加回答
举报
0/150
提交
取消