How to make sure docker's time syncs with that of the host?

前端 未结 17 1562
北恋
北恋 2020-12-02 07:10

I have dockers running on Linode servers. At times, I see that the time is not right on the dockers. Currently I have changed the run script in every docker to include the f

17条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 07:29

    Docker Usage

    Here's a complete example which builds a docker image for a go app in a multistage build. It shows how to include the timezone in your image.

    FROM golang:latest as builder
    
    WORKDIR /app
    
    ENV GO111MODULE=on \
        CGO_ENABLED=0 \
        GOOS=linux \
        GOARCH=amd64
    
    COPY go.mod .
    COPY go.sum .
    
    RUN go mod download
    
    COPY . .
    
    RUN go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main
    
    ### Certs
    FROM alpine:latest as locals
    
    RUN apk --update --no-cache add ca-certificates
    
    RUN apk add --no-cache tzdata
    
    ### App
    FROM scratch 
    
    WORKDIR /root/
    
    COPY --from=locals /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
    
    COPY --from=builder app/main .
    
    COPY --from=builder app/templates ./templates
    
    COPY --from=locals /usr/share/zoneinfo /usr/share/zoneinfo
    
    ENV TZ=Asia/Singapore
    
    EXPOSE 8000
    
    CMD ["./main"]
    

提交回复
热议问题