Search code examples
dockerasp.net-coreraspberry-pi.net-coredocker-swarm

ASP.NET Core running on a Raspberry Pi Swarm


I have a Docker Swarm with multiple Raspberry Pis (raspbian light). I try to run ASP.NET Core Containers on them as service / stack.

I have following Dockerfile:

FROM microsoft/dotnet:2.0-sdk AS build
WORKDIR /source
COPY WebApi.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /publish -r linux-arm /p:PublishWithAspNetCoreTargetManifest="false"

FROM microsoft/dotnet:2.0-runtime-deps-stretch-arm32v7
ENV ASPNETCORE_URLS http://+:80
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT [ "./WebApi" ]

What works: Building & pushing the container image on my win10 laptop (till the sdk image is only available for x64) and running the container on a single raspberry node with docker run:

docker run --rm -it myrepo/myimage
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

(so the container can run and it's no arm vs x64 issue)

What don't work:

docker service create myrep/myimage
2n4ahyhgb3ju5rvo97tekh9vg
overall progress: 0 out of 1 tasks
1/1: no suitable node (unsupported platform on 3 nodes)

And of course docker stack deploy.

If I inspect the created image (or even the arm32v7 image from microsoft) it just states amd64 instead of arm.

"Architecture": "amd64",
"Os": "linux",

So is it a case of wrong meta data? Which is only checked by docker if you use swarm? How can I change that / make it run? Building a base image on my own? Do I miss something?

Edit 1 I tried it with the .NET Core 2.1 images and had the same behavior.


Solution

  • With the latest .NET Core 2.1 Preview 2 images released yesterday it finally works.

    Update (add Dockerfile): This simple one should do the trick:

    FROM microsoft/dotnet:2.1-sdk-stretch-arm32v7 AS builder
    ENV DOTNET_CLI_TELEMETRY_OPTOUT 1
    WORKDIR /src
    COPY *.csproj .
    RUN dotnet restore
    COPY . .
    RUN dotnet publish -c Release -o /publish -r linux-arm
    
    FROM microsoft/dotnet:2.1-runtime-deps-stretch-slim-arm32v7
    WORKDIR /app
    COPY --from=builder /publish .
    ENTRYPOINT [ "./MyService" ]
    

    You can even build your image now on your raspberry pi. But be aware it´s still a (nice working) preview.