1

I need to change the date / time of my Azure App Service. This will help me in time travelling the API to a past date. I have used linux based image of .Net Core API, deployed as container in Azure App Service. In this API I have a method which currently returns the system date and time.

I know there is a way to set the timezone. This can be part of the dockerfile. I am trying to look for a similar way to change the date.

Manu
  • 331
  • 3
  • 15

1 Answers1

0

There are multiple ways to get the current time. You can set the right time zone then get the system current time.

You can follow the ways to set the time zone in the docker container or Dockerfile here. Also, you can set the time zone in Azure Web App while you deploy your application in it. Azure Web App uses the environment variable WEBSITE_TIME_ZONE to set the time zone. For more details, see AppService: Setting a time-zone with a WEBSITE_TIME_ZONE App Setting (and many more).

But I would suggest you just get the current UTC time and then calculate your time with the right time zone in your code. This is the best way to get the time as I think.

Update

As I think, what you need is to configure the SSH server in the custom image and then when you deploy the image to Azure Web App, you can ssh into the container to debug. So, you could follow the steps in SSH support for Azure App Service on Linux to configure the SSH server.

You can also set the date when you create the image from Dockerfile. Here is an example.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • Thanks Charles! As mentioned in my post , I was able to set the Time Zone. I had followed the same blog you had shared. But the issue I am facing is to set a different date in Azure App Service. The date would be a past date. – Manu Aug 19 '19 at 05:25
  • @Manu What do you mean to set a different date in Azure App Service? Do you mean an environment variable? – Charles Xu Aug 19 '19 at 06:07
  • I would like to set the system date of that container to a different date. This way we can Time travel that Application to different system date. – Manu Aug 19 '19 at 17:14
  • 1
    @Manu I don't think it's a good idea to set the date with a different date while all the app service running in the current time. If it's a test requirement then you need to ssh into the app container and change it on a different date, take a look at [SSH support for Azure App Service on Linux](https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-ssh-support). – Charles Xu Aug 20 '19 at 06:47
  • @Manu Any more questions? Does it wolve your problem? – Charles Xu Aug 23 '19 at 06:25
  • I will try that. I was hoping if something can be done from DockerFile or Docker Compose file it would have helped. Thanks for your help! – Manu Aug 23 '19 at 06:35
  • 1
    @Manu You can take a look at this [case](https://serverfault.com/questions/824631/how-to-set-system-time-dynamically-in-a-docker-container), but I'm not sure it's usable in Azure App Service. – Charles Xu Aug 23 '19 at 06:41
  • I did look at the [case](https://github.com/wolfcw/libfaketime) and was able to set a time in Azure App Service. Basically its a fake time. I included this library in my Docker Image.Set the below environment variable while deploying the App Service and it worked fine! -LD_PRELOAD "/usr/local/lib/faketime/libfaketime.so.1" -FAKETIME "-3d" – Manu Dec 24 '19 at 04:43
  • @Manu Glad to hear that. Then you can accept it as the answer to help other communities who are looking for this. – Charles Xu Dec 24 '19 at 06:03
  • Can you post that answer separately? Currently its part of a comment! Then I will accept it as answer! – Manu Dec 27 '19 at 06:29
  • @Manu I update the answer to add the info. Is that what you wish? – Charles Xu Dec 30 '19 at 01:54