Reputation: 14155
I have working Dockerfile content
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY ./Honda.Domain/Honda.Domain.csproj ./Honda.Domain/
COPY ./Honda.API/Honda.API.csproj Honda.API/
RUN dotnet restore Honda.API/Honda.API.csproj
# copy everything else and build app
COPY . ./
WORKDIR /app/Honda.API/
RUN dotnet publish -c Release -o publish/
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build /app/Honda.API/publish .
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
ENTRYPOINT ["dotnet", "Honda.API.dll"]
but when I try to optimize the image using alpine image instead of aspnet:3.1
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY ./Honda.Domain/Honda.Domain.csproj ./Honda.Domain/
COPY ./Honda.API/Honda.API.csproj Honda.API/
RUN dotnet restore Honda.API/Honda.API.csproj
# copy everything else and build app
COPY . ./
WORKDIR /app/Honda.API/
RUN dotnet publish -c Release -o publish/
FROM alpine:3.9.4 #**************************** change 1 ***************
# Add some libs required by .NET runtime
RUN apk add --no-cache libstdc++ libintl icu #* change 2***************
WORKDIR /app
COPY --from=build /app/Honda.API/publish .
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
ENTRYPOINT ["dotnet", "Honda.API.dll"]
but with the second image I'm getting error on docker-compose up --build
ERROR: for honda-api Cannot start service honda-api: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "dotnet": executable file not found in $PATH": unknown ERROR: Encountered errors while bringing up the project.
Any ideas?
Upvotes: 1
Views: 1465
Reputation: 9241
You should use:
FROM mcr.microsoft.com/dotnet/aspnet:3.1-alpine
This includes asp.net core 3.1 runtime on alpine linux 3.16
Please see: https://hub.docker.com/_/microsoft-dotnet-aspnet/
Upvotes: 0
Reputation: 2244
FROM alpine:3.9.4 #**************************** change 1 ***************
https://hub.docker.com/_/alpine - referring this link
Alpine Linux is a Linux distribution. The image is only 5 MB in size. So you essentially have go only a Linux vanilla machine.. You'll have to install the .NET Core Runtime.
Now you are right when you RUN apk add
sequence but it's not enough.
You'll have a lot more apk add
before you setup a fully functional .NET Core runtime.
And btw that's also against docker philosophy. The docker philosophy is that you let the creator of technology create a base image for you. With the owners creating the image you'll always be sure that it works.
While you focus completely on developing your end of the application.
In your case .NET Core image by Microsoft. I'd recommend docker pull mcr.microsoft.com/dotnet/runtime
If you want a smaller image pick the .NET Core Runtime image. The last time I checked it was about 200MB and it has everything for running a .net core dll or exe.
Upvotes: 1