简体   繁体   English

Kubernetes 不走 dockerfile 时区

[英]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. 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?为什么 kubernetes 吊舱不采用美国/波哥大时区?

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有关更多详细信息:在 azure 管道中,我可以看到正确的时区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 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我认为您可能正在以不同的图像定义 TZ

This is the publish image:这是publish图像:

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.这就是你设置 TZ 的地方。 This is the final image where the application runs:这是应用程序运行的final图像:

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

You are not setting TZ here.您没有在此处设置 TZ。 Adding the TZ here just like you did in the publish image should be sufficient, I think.我认为,就像您在publish图像中一样在此处添加 TZ 就足够了。

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"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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