Change TimeZone in Docker (ASP.NET Core) - c#

I am new to docker and wish to set TZ=Australia/NSW to the official dotnet core docker image
I tried adding to ENV TZ=Australia/NSW on line 5, but it didn't work.
Please help.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV TZ=Australia/NSW
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Application.WebAPI/Application.WebAPI.csproj", "Application.WebAPI/"]
RUN dotnet restore "Application.WebAPI/Application.WebAPI.csproj"
COPY . .
WORKDIR "/src/Application.WebAPI"
RUN dotnet build "Application.WebAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Application.WebAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Application.WebAPI.dll"]

The OS version for the aspnet image is Debian GNU/Linux 10
I ran two commands inside the docker container
ln -sf /usr/share/zoneinfo/posix/Australia/NSW /etc/localtime
date
And got the below output:
You could add this to your Dockerfile as part of the Docker build instruction
Run ln -sf /usr/share/zoneinfo/posix/Australia/NSW /etc/localtime

Related

The 'file' scheme is not supported

When I run with the below Dockerfile my.net API is exposing only in port 80 and shows "The 'file' scheme is not supported" whereas when I run this docker file through VisualStudio it exposes to 443 and works like a charm
Here is my docker file
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["RECashMachineBackend/RECashMachineBackend.csproj", "RECashMachineBackend/"]
COPY ["RECashMachineBackend.Repository/RECashMachineBackend.Repository.csproj", "RECashMachineBackend.Repository/"]
COPY ["RECashMachineBackend.Models/RECashMachineBackend.Models.csproj", "RECashMachineBackend.Models/"]
COPY ["RECashMachineBackend/nuget.config", ""]
# COPY ["*.props", "./"]
# ARG PAT=localhost
# RUN sed -i "s|</configuration>|<packageSourceCredentials><Techdome.Identity><add key=\"Username\" value=\"PAT\" /><add key=\"ClearTextPassword\" value=\"${PAT}\" /></Techdome.Identity></packageSourceCredentials></configuration>|" nuget.config
RUN dotnet restore "RECashMachineBackend/RECashMachineBackend.csproj" --configfile "./nuget.config"
COPY . .
WORKDIR "/src/RECashMachineBackend"
RUN dotnet build "RECashMachineBackend.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "RECashMachineBackend.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RECashMachineBackend.dll"]
With the Dockerfile, as shown, I'd only expect your app to be reachable on port 80.
That's because the aspnet image that you base your final image on, sets the environment variable ASPNETCORE_URLS to http://+:80.
Having EXPOSE 443 doesn't change that. EXPOSE is only documentation.
If you want your app to listen on port 443 as well, you should change the value of ASPNETCORE_URLS. I suspect that Visual Studio does that when it runs the container. You can do it by setting the variable in your Dockerfile, like this
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
ENV ASPNETCORE_URLS="http://+:80;https://+:443"
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["RECashMachineBackend/RECashMachineBackend.csproj", "RECashMachineBackend/"]
COPY ["RECashMachineBackend.Repository/RECashMachineBackend.Repository.csproj", "RECashMachineBackend.Repository/"]
COPY ["RECashMachineBackend.Models/RECashMachineBackend.Models.csproj", "RECashMachineBackend.Models/"]
COPY ["RECashMachineBackend/nuget.config", ""]
# COPY ["*.props", "./"]
# ARG PAT=localhost
# RUN sed -i "s|</configuration>|<packageSourceCredentials><Techdome.Identity><add key=\"Username\" value=\"PAT\" /><add key=\"ClearTextPassword\" value=\"${PAT}\" /></Techdome.Identity></packageSourceCredentials></configuration>|" nuget.config
RUN dotnet restore "RECashMachineBackend/RECashMachineBackend.csproj" --configfile "./nuget.config"
COPY . .
WORKDIR "/src/RECashMachineBackend"
RUN dotnet build "RECashMachineBackend.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "RECashMachineBackend.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RECashMachineBackend.dll"]
That will make your app listen on port 443 as well. But I think you're still missing copying a certificate into your dockerfile to use, when communicating over HTTPS.

Docker multistage build error c# (v20.10.8)

I have a microservice project and it includes docker. I am using .Net and .Net Framework. .Net 5.0 and .Net Framework 4.7.2
I don't get an error while building the project, but when I need to upload it to docker, I get an error. What is the solution ?
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Services/Customers/Wise.Customers/Wise.Customers.csproj",
"Services/Customers/Wise.Customers/"]
COPY ["Services/Customers/Wise.Customers.Application/Wise.Customers.Application.csproj",
"Services/Customers/Wise.Customers.Application/"]
COPY ["Services/Customers/Wise.Customers.Domain/Wise.Customers.Domain.csproj",
"Services/Customers/Wise.Customers.Domain/"]
COPY ["Services/Wise.Core/Wise.Core.csproj", "Services/Wise.Core/"]
COPY ["Services/Customers/Wise.Customers.Infrastructure/Wise.Customers.Infrastructure.csproj",
"Services/Customers/Wise.Customers.Infrastructure/"]
RUN dotnet restore "Services/Customers/Wise.Customers/Wise.Customers.csproj"
COPY . .
WORKDIR "/src/Services/Customers/Wise.Customers"
RUN dotnet build "Wise.Customers.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Wise.Customers.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Wise.Customers.dll"]
error;

how to include class library reference into docker file

i'm trying to build docker file for .net core application which is having reference of class library whenever i'm trying to build docker i'm getting below error.
Skipping project because it was not found
below is the docker file which i'm using
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "testapp.dll"]
You need to move the Dockerfile to the solution level, and reference the projects using [Folder]/[Project].csproj.
Here is my Dockerfile (located in the solution level):
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["SumApi/SumApi.csproj", "SumApi/"]
COPY ["Shared/Shared.csproj", "Shared/"]
RUN dotnet restore "SumApi/SumApi.csproj"
COPY . .
WORKDIR "/src/SumApi"
RUN dotnet build "SumApi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SumApi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app`enter code here`
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SumApi.dll"]
Learned it from here: https://imranarshad.com/dockerize-net-core-web-app-with-dependent-class-library/

Docker Can't Find Response in Postman

I'm using a Docker Compose file to run two Docker Containers One an Image I already published and one a build. I can not see the image when I go to the configured location.
Docker Compose
version: '3.4'
services:
twslogging:
image: ${DOCKER_REGISTRY-}twslogging
build:
context: .
dockerfile: twsLogging\Dockerfile
ports:
- '8000:8000'
twsUsers:
image: tbennet/twsusers
ports:
- '7000:7000'
DockerFile Loggin (One Built-in Docker compose Up)
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 8000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1803 AS build
WORKDIR /src
COPY ["twsLogging/twsLogging.csproj", "twsLogging/"]
RUN dotnet restore "twsLogging/twsLogging.csproj"
COPY . .
WORKDIR "/src/twsLogging"
RUN dotnet build "twsLogging.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "twsLogging.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "twsLogging.dll"]
DockerFile (Users Docker file that is published)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 7000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1803 AS build
WORKDIR /src
COPY twsUsers/nuget.config ./
COPY ["twsUsers/twsUsers.csproj", "twsUsers/"]
COPY ["twsDatabase/twsDatabase.csproj", "twsDatabase/"]
COPY . .
RUN dotnet restore "twsUsers/twsUsers.csproj" --configfile ./nuget.config
WORKDIR "/src/twsUsers"
RUN dotnet build "twsUsers.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "twsUsers.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "twsUsers.dll"]
PostMan
enter image description here
Ok, I found the answer thanks for the comments they helped me look in the right spot. So For .net Core, this is what you do. on your port the port localhost number then 80 so I changed my port to 7000:80 and ran the compose and it came up. I found the answer looking here https://github.com/dotnet/dotnet-docker/blob/master/samples/run-aspnetcore-https-development.md

How to build one docker image for multiple projects?

In my project I am using .net core 2.2 , recently I am using additional class library inside my project.
When I am trying to build my image it can not found my dll.
My docker file looks like:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
EXPOSE 80
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "LibvirtManagement.dll"]
I am getting error like this:
The project file "/JenkinsService/JenkinsService.csproj" was not found.
[/app/LibvirtManagement.sln]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
The error message is pretty straightforward, you're missing JenkinsService.csproj and other files from this project in docker container where you build it. You need to copy these files as well.
If you're using Visual Studio the easiest way to do it is to right-click executable project file (LibvirtManagement in your case) and then select Add -> Docker Support.... It will auto-generate correct Dockerfile for you
EDIT: this is what this tool created for me:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["LibvirtManagement/LibvirtManagement.csproj", "LibvirtManagement/"]
COPY ["JenkinsService/JenkinsService.csproj", "JenkinsService/"]
RUN dotnet restore "LibvirtManagement/LibvirtManagement.csproj"
COPY . .
WORKDIR "/src/LibvirtManagement"
RUN dotnet build "LibvirtManagement.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "LibvirtManagement.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "LibvirtManagement.dll"]

Categories

Resources