DEV Community

Goffity Corleone
Goffity Corleone

Posted on • Edited on

2 1

Docker container Timezone environment

เมื่อ develop application และมีการอ้างอิงเวลา โดยใช้ docker ในการทำงานนั้น อาจจะต้องเจอเรื่องปัญหาของ timezone คือ container ที่เราสร้างขึ้นจะได้ timezone ที่ตรงกับที่เราต้องการหรือเราอาจจะต้องการ timezone ที่ไม่ตรงกับเวลาที่เราพัฒนาอยู่

วิธีที่จะแก้ปัญหาคือ เวลาที่เราสร้าง container ขึ้นมาให้เรากำหนด timezone ของ container ตัวนั้นเข้าไปด้วย ตัวอย่างเช่น

FROM openjdk:8-jdk-alpine
ARG TIMEZONE="Asia/Bangkok"

# Set timezone
RUN apk add tzdata
RUN cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
RUN "date"
Enter fullscreen mode Exit fullscreen mode

สำหรับ slim หรือ ubuntu

FROM openjdk:11.0.8-jdk-slim
ENV TZ "Asia/Bangkok"
RUN date
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay