Exception when trying to containerize and publish StatelessService in Service Fabric Exception when trying to containerize and publish StatelessService in Service Fabric docker docker

Exception when trying to containerize and publish StatelessService in Service Fabric


I had the same issue but I achieved to containerize a stateless service in a different way than indicated in the microsoft documentation.

  1. microsoft/service-fabric-reliableservices-windowsservercore:1803 docker image has .Net Core runtime 2.0 installed. If your stateless service is running on later versions it won't work. For this reason, I built my docker image in this way docker image servicefabric-runtime.
  2. I realized SFBinaryLoader.cs class is not necessary for running Service Fabric Reliable Services or Reliable Actors inside containers. I didn't add it to my code.
  3. I didn't execute CreateDockerPackage.ps1 for build the container, I only modified ServiceManifest.xml for changing EntryPoint section as follow:
    <EntryPoint>      <ContainerHost>        <ImageName>statelesscontainer:0.1</ImageName>      </ContainerHost>    </EntryPoint>
  1. I changed my build project output path to pub/ and manually I added in the root of stateless service the Dockerfile based on step 1 as follow:
    FROM edalx/servicefabric-runtime:dotnetcore-3.1.2    WORKDIR /app    ADD pub .    CMD ["ApiService.exe"]
  1. Besides in ApplicationManifest.xml you need to add PortBinding tag.
  <ContainerHostPolicies CodePackageRef="Code" Isolation="process" ContainersRetentionCount="2">      <HealthConfig />      <PortBinding ContainerPort="0" EndpointRef="ServiceEndpoint" />      <ImageOverrides>         <Image Name="edalx.azurecr.io/statelesscontainer:0.1" />      </ImageOverrides>  </ContainerHostPolicies>
  1. I'm using Visual Studio Community 2019 and for deploying, it detects automatically it is a container and show the wizard like a non-containerized service and it will do all the work.

I tried using hyperv isolation but for me it didn't work.

You can find a complete example in my repo https://github.com/edalx/servicefabric-examples/tree/master/servicefabric-container