Search

Language:  
Search for:

Available article translations:

How do I change the system time or timezone in a container?

APPLIES TO:
  • Parallels Cloud Server
  • Parallels Virtuozzo Containers for Linux
  • Parallels Server

Question

How do I change the system time or timezone in a container?

Answer

You cannot change the system time in a container because all VEs on the Hardware Node have the same system time. However, it is possible to change the default system timezone inside a VE, for example, by replacing /etc/localtime with the file from /usr/share/zoneinfo, which contains the description of your timezone.

If it is required to have different time on the node and inside the containers, it will be required to tweak the OS template.

E.g. using centos-6-x86_64 OS template:

  1. Find the occurrence of "/etc/localtime" in any of the scripts of the OS template:

    [root@pcs ~]# grep localtime /vz/template/centos/6/x86_64/config/os/default/*
    /vz/template/centos/6/x86_64/config/os/default/post-cache:[ -f /etc/localtime ] && cp -fp /etc/localtime etc/localtime
    
  2. Comment such lines, if found:

    [root@pcs ~]# vi /vz/template/centos/6/x86_64/config/os/default/post-cache
    [root@pcs ~]# grep localtime /vz/template/centos/6/x86_64/config/os/default/post-cache
    #[ -f /etc/localtime ] && cp -fp /etc/localtime etc/localtime
    
  3. Add the following lines to the post-install script:

    [root@pcs ~]# vi /vz/template/centos/6/x86_64/config/os/default/post-install
    [root@pcs ~]# tail /vz/template/centos/6/x86_64/config/os/default/post-install
    
    # Force regeneration of mime-database, due to shared-mime-info
    # post-install script failure
    /usr/bin/update-mime-database /usr/share/mime > /dev/null 2>&1
    
    ## Move to a new time zone     <---------added
    rm -f /etc/localtime     <---------added
    ln -s /usr/share/zoneinfo/posix/Asia/Tokyo /etc/localtime     <---------added
    
    popd > /dev/null
    
  4. Recreate the OS template cache:

    [root@pcs ~]# vzpkg remove cache centos-6-x86_64 ; vzpkg create cache centos-6-x86_64
    

Once this is done, any new container, created on this OS template, will get the configured timezone. For existing containers, it's necessary to run the commands manually:

  # rm -f /etc/localtime
  # ln -s /usr/share/zoneinfo/posix/Asia/Tokyo /etc/localtime

Search words:

VPS timezone

/etc/localtime

date: cannot set date: Operation not permitted

change time

change timezone




eb0ea3b827d18de2329b6477e24c1d59 909d99074e442b52ce54cc7b31cf065d 2897d76d56d2010f4e3a28f864d69223 ca05eaf5b843fbd53589c90d7228a6df bf1c3a170005eae151f49ba2720abde9

FEEDBACK
Was this article helpful?
Tell us how we may improve it.
Yes No
 
 
 
 
 
 
Server Virtualization
- Parallels Cloud Server
- Parallels Containers for Windows 6.0
- Parallels Virtuozzo Containers
Automation
- Parallels Automation
- Parallels Automation for Cloud Infrastructure
- Parallels Business Automation Standard
- Parallels Virtual Automation
- Parallels Plesk Panel Suite
- Web Presence Builder
- Parallels Plesk Automation
- Parallels Small Business Panel
- Value-added Services for Hosters
- Parallels Partner Storefront
Services & Resources
- Cloud Acceleration Services
- Professional Services
- Support Services
- Training & Certification