临时修改:

在镜像中执行如下命令:不过改的只是shell的时间,要改系统时间需要打镜像。

yum install git -y
cd /root
git clone https://github.com/wolfcw/libfaketime
yum install gcc make -y
cd libfaketime/
make
make install

参考文章:

xiaoxiaoguo.cn/docker/faketime.html

在deployment中修改时间:但是这种方法会影响到整个节点所在的所有容器的时间。

    spec:
      containers:
      - image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
        securityContext:
          capabilities:
            add:
            - SYS_TIME

永久修改:在Dockerfile中添加如下

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' > /etc/timezone