dockerasp.net-coredockerfilenlogtzdata

Changing timezone in Asp.Net Core container


I am running my app in a container with the following base image:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base

When I publish the app, container timezone is Greenwich Mean Time and therefore my NLog entries in the database off by 6 hours.

I can change the timezone by entering into the container and running dpkg-configure tzdata and after restarting the container, my log entries become normal. However, I am wondering if this can be done through the Dockerfile or the run flags ?


Solution

  • I think you need to set ENV in your Dockerfile:

    ENV TZ=Europe/Berlin