My app is .net core 3.1 based. Trying to connect to kafka , publish and consume topics. Locally the code is working fine no error .Running the code in wsl2 ubuntu env using vs code. Now I want to create a docker image for the same code and publish in azure. The docker image is getting created but while trying to run the image getting error
No provider for SASL mechanism GSSAPI:Recompile librdkafka with libsasal2 or openssl support. Current build options:Plain Sasl_scram ouathbearer.
Please help with the docker file as what exactly to install and how to do so
Docker file :
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
RUN apt-get update
RUN apt-get install -y sasl2-bin \
libsasl2-modules-gssapi-mit\
krb5-user \
libkrb5-dev \
libsasl2-dev\
libzstd-dev
RUN echo "Done"
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["abc.csproj", "./"]
RUN dotnet restore "./abc.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./abc.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "abc.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "abc.dll"]
Related
It's my first question here so let me know if I have to change something or add more information.
We’re using AWS CodeArtifact for storing our packages and when we try to build a Docker image from our Dockerfile it fails because it's unable to load the source during the restore process.
We have a web API in .Net we want to deploy using AWS Fargate. This project runs smoothly from Visual Studio 2022 using Docker but we can’t build the image from PowerShell after adding our packages from CodeArtifact.
Our approach to include the credentials in the build is to pass the NuGet.Config stored on the host using Buildkit.
This’s our Dockerfile:
#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/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:49151
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . .
WORKDIR /src
COPY ["Src/Presentation/Project.API/Project.API.csproj", "Src/Presentation/Project.API/"]
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
--mount=type=secret,id=nugetconfig \
dotnet restore "Src/Presentation/Project.API/Project.API.csproj" \
--configfile /run/secrets/nugetconfig
COPY . .
WORKDIR "/src/Src/Presentation/Project.API"
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet build "Project.API.csproj" -c Release -o /app/build \
--no-restore
FROM build AS publish
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet publish "Project.API.csproj" -c Release -o /app/publish \
--no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.API.dll"]
Our script in PowerShell:
docker buildx build --secret id=nugetconfig,src=$HOME\AppData\Roaming\NuGet\NuGet.Config -f "Src\Presentation\Project.API\Dockerfile" -t my-dotnet-image .
Output:
#14 [build 6/9] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages --mount=type=secret,id=nugetconfig dotnet restore "Src/Presentation/Project.API/Project.API.csproj"
--configfile /run/secrets/nugetconfig
#14 1.175 Determining projects to restore...
#14 2.504 /src/Src/Presentation/Project.API/Project.API.csproj : error NU1301: Unable to load the service index for source
https://domain-123456789012.d.codeartifact.us-east-2.amazonaws.com/nuget/repository/v3/index.json.
What are we missing here? Once we have the Dockerfile working we want to use CDK for deploying the Docker image alongside our infrastructure.
We’re using aws codeartifact login command to authenticate with the service. We work on windows with a Linux container
I'm rookie in Docker and I have a problem. I've created Docker support to my app because i want transfer it to Linux. And locally all works fine but when i push my image to docker hub and start it on linux i got a problem with config
enter image description here
So, this is dockerfile
FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Shiki/Shiki.csproj", "Shiki/"]
COPY ["Shiki.Data/Shiki.Data.csproj", "Shiki.Data/"]
COPY ["Shiki.Commands/Shiki.Commands.csproj", "Shiki.Commands/"]
COPY ["Shiki.Service/Shiki.Service.csproj", "Shiki.Service/"]
RUN dotnet restore "Shiki/Shiki.csproj"
COPY . .
WORKDIR "/src/Shiki"
RUN dotnet build "Shiki.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Shiki.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Shiki.dll"]
Before i tried to push value in docker-compose and it doesn't work too. So, i will attach a file folders, probably it will help to solve a problem.
VS:
enter image description here
Docker:
enter image description here
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;
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
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"]