I can't figure out how to change timezone from UTC inside of docker container.
I would love to have docker time same as my host machine time(utc+1) but nothing i tried worked.
Time is always set as UTC.
Thanks for trying to help.
Here is my code!
Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 5010
ENV ASPNETCORE_URLS=http://+:5010
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY . .
RUN apt-get update && \
apt-get install -yq tzdata && \
ln -fs /usr/share/zoneinfo/Europe/Belgrade /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
ENV TZ="Europe/Belgrade"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM build AS publish
RUN dotnet publish "Restoran.Api" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Restoran.Api.dll"]
and here is docker-compose.yml
version: '3'
services:
#mssql docker
restoran-sql:
image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
restart: unless-stopped
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=QWEqwe123!
- MSSQL_PID=Developer
ports:
- 1401:1433
networks:
- restorannet
restoran-api:
restart: unless-stopped
build:
context: .
environment:
- ConnectionStrings:testCon=Server=restoran-sql,1433;Database=testDb;User=sa;Password=QWEqwe123!;ConnectRetryCount=0
ports:
- 49857:5010
networks:
- restorannet
links:
- restoran-sql
depends_on:
- restoran-sql
networks:
restorannet:
driver: bridge
In Dockerfile i tried adding
ENV TZ=Europe/Belgrade
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
and placed it right below this line
ENV ASPNETCORE_URLS=http://+:5010
and in docker-compose.yml i tried adding these changes but nothing seems to work
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=QWEqwe123!
- MSSQL_PID=Developer
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
and for api image
restoran-api:
restart: unless-stopped
build:
context: .
environment:
- ConnectionStrings:testCon=Server=restoran-sql,1433;Database=testDb;User=sa;Password=QWEqwe123!;ConnectRetryCount=0
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"