Dockerfile set the time zone alpine

background:

Recently wrote golang related code. Which uses a correlation function of time of the operation, as follows:

 

nowTime := time.Now()
nUnixEndTime := nowTime.Unix()
nHour, nMin, nSec := nowTime.Clock()

But the code running in the docker container, taken wrong time. Reason is inconsistent region time zone when the container with the machine.

deal with:

Docker container set time zone, Dockerfile following settings:

FROM alpine

LABEL license='SPDX-License-Identifier: Apache-2.0' \
      copyright='Copyright (c) 2018'

# The main mirrors are giving us timeout issues on builds periodically.
# So we can try these.
ENV TZ=Asia/Shanghai
# RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories
RUN echo "http://mirrors.aliyun.com/alpine/v3.4/main/" > /etc/apk/repositories \
    && apk --no-cache add tzdata zeromq \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo '$TZ' > /etc/timezone

ps:

Due to the alpine zone sometimes did not mirror the relevant package, you need to download and install the job. And set the timezone and localtime East eight districts

Guess you like

Origin www.cnblogs.com/huoqs/p/10975375.html