Docker容器时区设置与中文字符支持

时区设置(通过Dockerfile)

ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

或者也可以直接这样:

# Set the timezone.
RUN sudo echo "America/New_York" > /etc/timezone
RUN sudo dpkg-reconfigure -f noninteractive tzdata

更多参考:
http://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes
https://github.com/docker/docker/issues/12084
http://tedwise.com/2015/05/02/setting-the-timezone-in-a-docker-image

中文支持

新建Dockerfile

FROM ubuntu:trusty

# Ensure UTF-8 locale
#COPY locale /etc/default/locale
RUN locale-gen zh_CN.UTF-8 &&\
  DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
RUN locale-gen zh_CN.UTF-8  
ENV LANG zh_CN.UTF-8  
ENV LANGUAGE zh_CN:zh  
ENV LC_ALL zh_CN.UTF-8  

然后执行构建

docker build -t xbyubuntu .

更多参考:
http://stackoverflow.com/questions/28405902/how-to-set-the-locale-inside-a-docker-container
https://github.com/abevoelker/docker-ubuntu-locale/blob/master/Dockerfile
http://blog.shiqichan.com/Input-Chinese-character-in-docker-bash/

    原文作者:xbynet
    原文地址: https://segmentfault.com/a/1190000005026503
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞