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"]
Related
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"]
When I run docker with Asp.net Core locally everything is ok. But when I use the Ubuntu virtual machine in cloud.google, I kind of start the container and everything works. But I don't know how to open the site. Login via External ip doesn't open anything. I just have "Can't access the site" Although everything opens locally. Am I missing any settings?
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Command: sudo docker run -d -p 8000:80 gamehomm/webapplication1
I got it!
docker run -d -p 80:80/tcp gamehomm/webapplication1
Then I changed VM instance details
Firewalls
Allow HTTP traffic
Allow HTTPS traffic
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 would like to make REST calls to my ASP Core Web Api running in Docker by using Postman. Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["MyApp.API/MyApp.API.csproj", "MyApp.API/"]
RUN dotnet restore "MyApp.API/MyApp.API.csproj"
COPY . .
WORKDIR "/src/MyApp.API"
RUN dotnet build "MyApp.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyApp.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.API.dll"]
Using Visual Studio 2019, I click on the Docker run button which builds the image and creates a container. However, Postman cannot access the API running in Docker. The error message is "Error: connect ECONNREFUSED 127.0.0.1:51005." Is there a port command that I should use? If so, where should I put it? Thanks.
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"]