I'm attempting to run my ASP NET Core 3.1 API in a Linux Docker container. A component in my API requires a connection via ODBC to a server located on an external server. While in debug mode when I startup my API, the connection is attempted via ODBC but fails with the error "libodbc could not be loaded" I assume the ODBC drivers are missing in the Docker container.
I have searched online and I haven't been able to find how I would go about adding the missing library to my container or if maybe I need to download a different Base image. A copy of my docker file can be found below.
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 ["Sample.Service/Sample.Service.csproj", "Sample.Service/"]
COPY ["../Libs/ExternalServices.Configure/ExternalServices.Configure.csproj", "../Libs/ExternalServices.Configure/"]
RUN dotnet restore "Sample.Service/Sample.Service.csproj"
COPY . .
WORKDIR "/src/Sample.Service"
RUN dotnet build "Sample.Service.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Sample.Service.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Sample.Service.dll"]
After looking deeper into the problem, I was missing a couple of key things to make it work. I did need to add the Linux commands to ensure the repositories are updated and then make a request to install the unixodbc library. The resulting Docker file looks like this.
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
RUN apt-get update
RUN apt-get install -y unixodbc
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Sample.Service/Sample.Service.csproj", "Sample.Service/"]
COPY ["../Libs/ExternalServices.Configure/ExternalServices.Configure.csproj", "../Libs/ExternalServices.Configure/"]
RUN dotnet restore "Sample.Service/Sample.Service.csproj"
COPY . .
WORKDIR "/src/Sample.Service"
RUN dotnet build "Sample.Service.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Sample.Service.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Sample.Service.dll"]
Related
I'm new to Docker and I have run into a trouble running my app in docker due missing ssl certificates. How do I run aspnetcore application in docker with non-development environment using dev certificates?
I have the following Dockerfile generated by Visual Studio:
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 ["MyApp/MyApp.csproj", "MyApp/"]
COPY [...other libraries...]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
When I run it from the Visual Studio with the default setup (development), it connects Docker and everything runs fine. However, I want to use a different appsettings file (appsettings.docker.json) because I need some different values when running in Docker and I'm already using my appsettings.development.json for my standard run from the VS. Thus I set ASPNETCORE_ENVIRONMENT=Docker. This is causing a pain as I'm suddenly getting an InvalidOperationException:
System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
Based on this answer, I have figured out that dotnet generates the dev certs automagically when the environment variable is Development. How can that be fixed for a differently called environment?
I did try to use the dotnet dev-certs https command in the Dockerfile, however, build failed saying that there is no sdk in the image and thus doesn't know the command.
Try adding these 2 lines
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
# Add the line below ---------------------------------------------------
RUN dotnet dev-certs https
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
COPY [...other libraries...]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
# Add the line below ---------------------------------------------------
COPY --from=publish /root/.dotnet/corefx/cryptography/x509stores/my/* /root/.dotnet/corefx/cryptography/x509stores/my/
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
I have a small application that I want to containerize in .Net5.0. It works well outside docker but if added RUN dotnet ef database update to my docker file, it gives a build error. I don't know if I placed it in a wrong place or it doesn't work that way.
Also will COPY --from=publish /app/publish/tomix.db . copy the new database file correctly?
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["API/API.csproj", "API/"]
RUN dotnet ef database update
RUN dotnet restore "API/API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish/tomix.db .
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API.dll"]
UPDATE This is the error after running dotnet build -t tomix .
AFAIK, the dotnet ef tool is no longer part of the .NET SDK, and needs to be explicitly installed. I.e., before attempting to RUN dotnet ef database update you must RUN dotnet tool install dotnet-ef
I created a blazor project using .netcore3.1.
I use PhysicalFileProvider in startup.cs.
I ran it with docker using config in docker.
The build was successful, but an exception occurred during execution.
The docker file is as follows:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["Web/Web.csproj", "Web/"]
RUN dotnet restore "Web/Web.csproj"
COPY . .
WORKDIR "/src/Web"
RUN dotnet build "Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Web.dll"]
This is a docker file automatically generated by Visual Studio.
Why can't the program find the directory?
Or, is there another way to find the directory?
I'm creating a new empty ASP.NET Core 2.2 with Docker support enabled (Docker for Windows).
When I run it on Docker, it does not connect to SQL Server. I was expecting that the nanoserver had a SQL Server in it. Am I wrong?
How should I connect this instance to an SQL Server?
I was trying to avoid creating a second Docker instance for the SQL Server. Is this the only way to achieve what I'm looking for?
Here's the auto generated Dockerfile:
FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS build
WORKDIR /src
COPY ["DockerTest2/DockerTest2.csproj", "DockerTest2/"]
RUN dotnet restore "DockerTest2/DockerTest2.csproj"
COPY . .
WORKDIR "/src/DockerTest2"
RUN dotnet build "DockerTest2.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "DockerTest2.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "DockerTest2.dll"]
I know this question was asked but nobody answer it.
I'm building web API on Core 2.2 with JWT token bearer. In token request I added check if user exist on our LDAP.
All working properly on IIS and console app but when I run with docker I'm getting:
"Unable to load DLL 'activeds.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
error.
If user exist all working fine but when user not exist Im checking user status with:
UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
Which causing error above.
Im new to docker. I have tried to play with images:
mcr.microsoft.com/dotnet/core/sdk
mcr.microsoft.com/dotnet/core/aspnet
microsoft/aspnetcore-build
In all cases the same result
I have exposed LDAP ports in docker file (or I think I exposed) and still getting the same error.
My current dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 383
EXPOSE 636
FROM mcr.microsoft.com/dotnet/core/sdk AS build
WORKDIR /src
COPY ["USITWebApi/USITWebApi.csproj", "USITWebApi/"]
RUN dotnet restore "USITWebApi/USITWebApi.csproj"
COPY . .
WORKDIR "/src/USITWebApi"
RUN dotnet build "USITWebApi.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "USITWebApi.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "USITWebApi.dll"]
I'm using Windows containers.
I spent three days trying to solve this. If you have any ideas please help me solve this issue.
Looks that it is a limitation based on the image that you are using as base. If you would like to use LDAP use any server core image based on your host OS. This is what I am doing. This is a example for Windows 2019 Server as host.
FROM mcr.microsoft.com/windows/servercore:ltsc2019 AS base
WORKDIR /app
EXPOSE 80
RUN powershell Set-ExecutionPolicy RemoteSigned
RUN powershell iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell choco install dotnet-6.0-runtime -Y
RUN powershell choco install dotnet-6.0-sdk -y
ENV ASPNETCORE_URLS=http://+80
RUN powershell fsutil behavior set symlinkEvaluation L2L:1 L2R:1 R2R:1 R2L:1
RUN powershell Set-ExecutionPolicy Bypass -Scope Process
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["src/Your.ProjectFile.csproj", "src/Your.Project.Folder/"]
COPY ["./NuGet.Config", "src/Your.Project.Folder"]
RUN dotnet restore "src/Your.Project.Folder/Your.ProjectFile.csproj"
COPY . .
WORKDIR "/src/src/Your.Project.Folder"
RUN dotnet build "Your.ProjectFile.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Your.ProjectFile.csproj" -c Release -o /app/publish
FROM base
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Your.ProjectFile.dll"]