i tried to containerize a simple Service Fabric Project into a Service Fabric Container Project.
I used the Create your first Service Fabric container application on Windows manual (https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/service-fabric/service-fabric-get-started-containers.md).
So at the first step i defined my docker image from VotingData service. I just made an own solution out of the service and just added the dockerfile and built it.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
ADD . .
RUN dotnet publish \
-c Release \
-o ./output
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/output .
EXPOSE 8000
ENTRYPOINT VotingData.exe
Then i pushed it into my azure image registry, and added it into my Service Fabric application as a container service, like the steps in the manual.
After Starting the SF cluster the Application and nodes are starting in the SF explorer after a while. The Problem is, the local VotingData container is just running for a view seconds.
When i debug into the error exited container i get this log:
$ docker logs sf-4-1a5af364-f71e-4d06-b713-76a6150f92db_d9bda8c5-561c-47c1-88f3-15391d3d2ae3
[17:34:34 INF] Start register Service
Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Fabric.Common.AppTrace' threw an exception.
---> System.DllNotFoundException: Unable to load DLL 'FabricCommon.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
at System.Fabric.Interop.NativeCommon.FabricGetConfigStore(Guid& riid, IFabricConfigStoreUpdateHandler2 updateHandler)
at System.Fabric.Common.NativeConfigStore.CreateHelper(IFabricConfigStoreUpdateHandler2 updateHandler)
at System.Fabric.Common.NativeConfigStore.<>c__DisplayClass3_0.<FabricGetConfigStore>b__0()
at System.Fabric.Interop.Utility.WrapNativeSyncInvoke[TResult](Func`1 func, String functionTag, String functionArgs)
at System.Fabric.Interop.Utility.<>c__DisplayClass27_0`1.<WrapNativeSyncInvokeInMTA>b__0()
at System.Fabric.Interop.Utility.RunInMTA[TResult](Func`1 func)
at System.Fabric.Interop.Utility.WrapNativeSyncInvokeInMTA[TResult](Func`1 func, String functionTag)
at System.Fabric.Common.NativeConfigStore.FabricGetConfigStore(IConfigStoreUpdateHandler2 updateHandler)
at System.Fabric.Common.Tracing.TraceConfig.InitializeFromConfigStore(Boolean forceUpdate)
at System.Fabric.Common.AppTrace..cctor()
--- End of inner exception stack trace ---
at System.Fabric.Common.AppTrace.get_TraceSource()
at System.Fabric.Interop.AsyncCallOutAdapter2`1.Start(CancellationToken cancellationToken)
at System.Fabric.Interop.AsyncCallOutAdapter2`1.WrapNativeAsyncInvoke(String functionTag, Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, Boolean runContinuationsAsynchronously)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvoke[TResult](Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, Boolean runContinuationsAsynchronously, String functionTag)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvoke[TResult](Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, String functionTag)
at System.Fabric.Interop.Utility.<>c__DisplayClass20_0`1.<WrapNativeAsyncInvokeInMTA>b__0()
at System.Fabric.Interop.Utility.RunInMTA[TResult](Func`1 func)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvokeInMTA[TResult](Func`2 beginFunc, Func`2 endFunc, InteropExceptionTracePolicy tracePolicy, CancellationToken cancellationToken, String functionTag)
at System.Fabric.Interop.Utility.WrapNativeAsyncInvokeInMTA[TResult](Func`2 beginFunc, Func`2 endFunc, CancellationToken cancellationToken, String functionTag)
at System.Fabric.FabricRuntime.NativeFabricRuntimeFactory.GetNodeContextAsync(TimeSpan timeout, CancellationToken cancellationToken)
at System.Fabric.FabricRuntime.GetNodeContextAsync(TimeSpan timeout, CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.RuntimeContext.GetOrCreateAsync(TimeSpan timeout, CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.ServiceRuntime.RegisterServiceAsync(String serviceTypeName, Func`2 serviceFactory, TimeSpan timeout, CancellationToken cancellationToken)
at VotingData.Program.Main() in C:\app\Program.cs:line 37
So in my eyes the problem is, that the SF cannot register the containerized service in the program.cs in the main method when it calls registerServiceAsync(). But the image is missing the dependency to the SF or something else.
private static void Main()
{
try
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Information()
.WriteTo.File(@"c:\temp\VotingDataLog.txt",
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true)
.CreateLogger();
// The ServiceManifest.XML file defines one or more service type names.
// Registering a service maps a service type name to a .NET type.
// When Service Fabric creates an instance of this service type,
// an instance of the class is created in this host process.
Log.ForContext<VotingData>().Information("Start register Service");
ServiceRuntime.RegisterServiceAsync("VotingDataType",
context => new VotingData(context)).GetAwaiter().GetResult();
Log.ForContext<VotingData>().Information("Service registered");
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(VotingData).Name);
// Prevents this host process from terminating so services keep running.
Thread.Sleep(Timeout.Infinite);
}
catch (Exception e)
{
ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
throw;
}
I also tried another option, so i added an image with the SF runntime. I used the edalx/servicefabric-runtime:dotnetcore-3.1.2 image from https://github.com/edalx/servicefabric-runtime
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
ADD . .
RUN dotnet publish \
-c Release \
-o ./output
FROM edalx/servicefabric-runtime:dotnetcore-3.1.2
WORKDIR /app
COPY --from=build-env /app/output .
EXPOSE 8000
ENTRYPOINT VotingData.exe
Then i got this error
$ docker logs sf-3-ed4968b2-0783-4550-9e26-8fe2c4879851_dcdc6636-359d-40ca-b499-e0e3ad805dca
[16:44:51 INF] Start register Service
Unhandled exception. System.Fabric.FabricException: An error occurred during this operation. Please check the trace logs for more details.
---> System.Runtime.InteropServices.COMException (0x80071CC0): 0x80071CC0
at System.Fabric.Interop.NativeRuntime.FabricEndGetNodeContext(IFabricAsyncOperationContext context)
at System.Fabric.FabricRuntime.NativeFabricRuntimeFactory.GetNodeContextEndWrapper(IFabricAsyncOperationContext context)
at System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext context, Boolean expectedCompletedSynchronously)
--- End of inner exception stack trace ---
at Microsoft.ServiceFabric.Services.Runtime.RuntimeContext.GetOrCreateAsync(TimeSpan timeout, CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.ServiceRuntime.RegisterServiceAsync(String serviceTypeName, Func`2 serviceFactory, TimeSpan timeout, CancellationToken cancellationToken)
at VotingData.Program.Main() in C:\app\Program.cs:line 37
So the dependency was there but the main method errored when it called registerServiceAsync().
User contributions licensed under CC BY-SA 3.0