Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Dockerfile set the default time zone

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to set the default time zone in Dockerfile". In daily operation, I believe many people have doubts about how to set the default time zone in Dockerfile. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to set the default time zone in Dockerfile". Next, please follow the editor to study!

The basic images we use when packaging images are basically UTC (Green time), which is 8 hours different from our commonly used Beijing (Shanghai) time (CST). When creating a container, we can hang the directory files related to the host time zone on the container:

Docker run-- rm-it-v / etc/localtime:/etc/localtime ubuntu# enters the container, date test root@3e6c1d137e02:/# dateMon Aug 5 15:26:20 CST 2017

This method is relatively troublesome. Each time you create a new container, you need to mount the configuration directory / file related to the time zone of the host machine. To simplify this step, you can package a new image through Dockerfile and change the default time zone of the container. The following are implemented in three basic system images:

Ubuntu

To use ubuntu as the basic image, you need to download and install the tzdata package first. The default time zone is UTC time zone. Modify the configuration file, and reset the time zone configuration through dpkg-reconfigure. After the installation is completed, in order to minimize the physical strength of the mirror, delete all kinds of unnecessary files generated during the installation.

FROM ubuntu MAINTAINER fastjrun ENV TIME_ZONE Asia/Shanghai RUN sed-is @ / archive.ubuntu.com/@/mirrors.aliyun.com/@g / etc/apt/sources.list\ & & apt-get update\ & & apt-get install-y tzdata\ & & ln-snf / usr/share/zoneinfo/$TIME_ZONE / etc/localtime & & echo $TIME_ZONE > / etc/timezone\ & & dpkg-reconfigure-f noninteractive tzdata\ & & apt-get clean\ & & rm-rf / tmp/* / var/cache/* / usr/share/doc/* / usr/share/man/* / var/lib/apt/lists/*Alphine

Alphine claims to be the smallest Linux system image (only 5m). First, use the apk package manager to install the tzdata package and set up the relevant configuration files.

FROM alpineMAINTAINER igitlib RUN apk add-- no-cache tzdata\ & & cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime\ & & echo "Asia/Shanghai" > / etc/timezone\ & & apk del tzdataCentos

Centos is relatively simple, just add a configuration file.

FROM centos ENV TIME_ZONE Asia/Shanghai RUN ln-snf / usr/share/zoneinfo/$TIME_ZONE / etc/localtime at this point, the study on "how to set the default time zone for Dockerfile" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report