Unable to Change Timezone in Azure Container Instance

Larry Lau 116 Reputation points
2021-11-19T18:31:33.867+00:00

I am running some PowerShell scripts in a container in ACI (Windows). I need the script to run in a specific time zone say Mountain Standard Time. Here is what I try so far and nothing works:

  1. In my Dockerfile, I add this line
    RUN Set-TimeZone -Id 'Mountain Standard Time'
    This works when I run the image locally in Docker Desktop. But in ACI, Get-TimeZone returns UTC.
  2. Set the TZ environment variable to Mountain Standard Time. The Windows container ignore this variable in both Docker Desktop and ACI.
  3. In my PowerShell, I run the Set-TimeZone at runtime when the container start up.
    I got this error in ACI but work in Docker Desktop Set-TimeZone : Access is denied
    At C:\app\Import-Invoices.ps1:59 char:5
    • Set-TimeZone -Id $ENV:TZ
    • ~~~~~~~~~~~~~~~~~~~~~~~~
      • CategoryInfo : FromStdErr: (:) [Set-TimeZone], Win32Exception
      • FullyQualifiedErrorId : SetTimeZoneFailed,Microsoft.PowerShell.Commands.
        SetTimeZoneCommand

I don't know what else I can try. has anyone been able to set the timezone of your container in Azure ACI?

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
669 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Pradeep Kommaraju 2,551 Reputation points
    2021-11-19T22:28:26.753+00:00

    Hi anonymous user-lau

    Thank you for reaching out to Microsoft Q & A Platform .

    Regarding this use case , I wasn't able to change the time frame of my ACI containers as az container update is not an available option today .
    Ref: https://video2.skills-academy.com/en-us/cli/azure/container?view=azure-cli-latest#az_container_create

    But i was able to set the time zone of the container while creating a new container using the following command:
    az container create --resource-group ACitest --location southindia --name newtime --image myimage:image1 --command-line "ping localhost" --os-type Linux -e "TZ=America/Chihuahua"

    here is the output:
    151092-image.png

    Ref about what are the variable that we need to use for Tz: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

    Hope this helps .

    Thanks & Regards,
    Pradeep

    ---------------------------------------

    Please do remember to accept the answer if it helps in solving your use case


  2. Isshak Darwich 0 Reputation points
    2024-05-16T19:32:32.5866667+00:00

    Nowadays (2024) you can set the TimeZone on Dockerfile with tzutil /s "desired timezone"
    List of timezones: https://video2.skills-academy.com/en-us/windows-hardware/manufacture/desktop/default-time-zones

    FROM mcr.microsoft.com/windows/servercore:ltsc2019
    
    WORKDIR /app
    
    RUN tzutil /s "SE Asia Standard Time"
    
    COPY ./ .
    
    0 comments No comments