如何在谷歌云运行中更改时区



我们的云运行时区默认为GMT,我需要将时区更改为BST。有办法在谷歌云运行中更改时区吗?

您可以像这样更改容器本地时间

FROM ubuntu
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata
RUN rm /etc/localtime && ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

编辑1

这是我的测试代码。

main.go

package main
import (
"fmt"
"net/http"
"time"
)
func main() {
http.HandleFunc("/", Date)
http.ListenAndServe(":8080", nil)
}
func Date(w http.ResponseWriter, r *http.Request) {
fmt.Println(time.Now())
fmt.Fprint(w, time.Now())
}

Dockerfile

FROM golang:1.17 AS builder
# Set necessary environmet variables needed for our image
ENV GO111MODULE=on 
CGO_ENABLED=0 
GOOS=linux 
GOARCH=amd64
# Move to working directory /build
WORKDIR /build
# Copy the code into the container
COPY . .
# Build the application
RUN go build -o main .
FROM ubuntu
COPY --from=builder /build/main /
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata
RUN rm /etc/localtime && ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
ENTRYPOINT ["/main"]

部署、卷曲命令和结果

gcloud run deploy --source=. --platform=managed --region=us-central1 --allow-unauthenticated changetimezone
curl https://changetimezone-<hash>-uc.a.run.app
-> Result: 
2022-04-12 06:32:40.688742034 -0700 PDT m=+0.069703450

相关内容

  • 没有找到相关文章

最新更新