简体   繁体   中英

Kubernetes not take dockerfile timezone

I have the next docker file where I have defined timeZone to America/Bogota, then where The Azure pipeline build the image I can see in the log date is correct from dockerfile, but when I exec the pod in azure Kubernetes the timezone is different. Why the kubernetes pod don't take timezone America/Bogota?

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src

COPY NuGet.Config ./
COPY NugetPackage/travelExpensesRestClient.1.0.0.nupkg NugetPackage/
RUN dir /src/NugetPackage

COPY microservicioX/microservicioX.csproj microservicioX/
COPY travelExpenses.Viajes.Proxy/travelExpenses.Viajes.Proxy.csproj travelExpenses.Viajes.Proxy/

RUN dotnet restore -nowarn:msb3202,nu1503  microservicioX/microservicioX.csproj #--verbosity diag
COPY . .
WORKDIR /src/microservicioX
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish microservicioX.csproj -c Release -o /app


WORKDIR /
ENV TZ=America/Bogota
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN date


FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "microservicioX.dll"]

For more Details: in the azure pipeline I can see the correct timezone https://i.ibb.co/wgSzHS9/Time-Zone-build-Image.png

Time Zone in the azure kubernetes pod https://i.ibb.co/hm25Xkc/Time-Zone-in-Pod.png

I think you might be defining the TZ in a different image

This is the publish image:

FROM build AS publish
RUN dotnet publish microservicioX.csproj -c Release -o /app


WORKDIR /
ENV TZ=America/Bogota
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN date

And that's where you set the TZ. This is the final image where the application runs:

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "microservicioX.dll"]

You are not setting TZ here. Adding the TZ here just like you did in the publish image should be sufficient, I think.

Omair Majid that's correct. This my finall code

FROM base AS final
WORKDIR /
ENV TZ=America/Bogota
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN date

WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "travelExpenses.Viajes.Api.dll"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM