In my last article, I wrote about how to create a single-page Angular app using the .NET Core CLI, create a Docker image, and run it as a container in about 4 steps that take just minutes to execute. By modifying a single line in your Dockerfile, you can target the 32-bit ARM architecture needed to run the image as a container on a Raspberry Pi.
Here’s the one line that needs to change in the Dockerfile to make it runnable on ARM32 (old line is commented for reference):
# FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.2-buster-slim-arm32v7 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build WORKDIR /src COPY ["my-app.csproj", "./"] RUN dotnet restore "./my-app.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "my-app.csproj" -c Release -o /app/build RUN apt-get update && \ apt-get install -y wget && \ apt-get install -y gnupg2 && \ wget -qO- https://deb.nodesource.com/setup_10.x | bash - && \ apt-get install -y build-essential nodejs FROM build AS publish RUN dotnet publish "my-app.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "my-app.dll"]
Note that the official list of available tags for different architectures can be found here. Consult this list to determine if newer images are available.
That’s it, though. Create your image, push it to Docker Hub, pull it on your Raspberry Pi, and run it just as you would locally. If you haven’t used Docker Hub before, you’ll need to login and create a repository. Check out the Docker Hub Quickstart for help. You may also need to run docker login
on both machines to access your new repo.
# dev machine
docker build -t <dockerID>/repo .
docker push <dockerID>/repo
# raspberry pi
docker pull <dockerID>/repo
docker run -d -p 5000:80 <dockerID>/repo

dotnet new Angular
app running locally on Raspberry Pi.