From Visual Studio, I've created a default ASP.NET Core Web Application with enabled Docker support.
It's using the default Microsoft Offical image for Linux container.
Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication1.csproj", ""]
RUN dotnet restore "./WebApplication1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
I want to install Microsoft Windows Fonts on it, I tried the following but it's not working:
RUN apt install ttf-mscorefonts-installer
How can I install fonts on this container?
Fonts can also be installed using graphical applications like GNOME fonts (the package is called gnome-fonts-viewer ). To install a font using such application, we open the font file with it: a preview of the font will be displayed. To proceed with the installation, we just click on the “install” button:
After a few days research, I haven’t got much progress about why the only font in mcr.microsoft.com.windows/servercore:ltsc2019 based image is lucon.ttf, and seems there’s no published method to add additional fonts to windows server core 2019 image.
Most importantly register the font & fontLInk carefully. Copy required fonts either from your local machine (C:\Windows\Fonts) or from mcr.microsoft.com/windows container image (you can use volume binding while running the container to copy fonts) Register the copied fonts. Register the FontLink for the copied fonts.
Congratulations you were able to successfully run an Asp.Net Core App on Linux (Ubuntu 18.04 LTS) Operating System. In this tutorial you have learned how to deploy an ASP.NET Core MVC App as well as install Nginx web server on Linux Ubuntu 18.04 LTS Azure virtual machine.
Got it. Revise the start of your Dockerfile as follows:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
#Add these two lines
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
WORKDIR /app
EXPOSE 80
[...]
The first line updates the default /etc/apt/sources.list file in the Linux OS to include the 'contrib' archive area (which is where ttf-mscorefonts-installer lives). That ensures apt-get can find it and install it as normal in the second line (along with fontconfig, which you'll also need.)
For the record, this page suggested using the "fonts-liberation" package instead of ttf-mscorefonts-installer, which you can also get working with two different lines at the start of the Dockerfile as follows:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
#Add these two lines for fonts-liberation instead
RUN apt-get update; apt-get install -y fontconfig fonts-liberation
RUN fc-cache -f -v
WORKDIR /app
EXPOSE 80
[...]
you can copy your custom fonts to the docker images and install fonts like this
RUN apt-get -y install fontconfig
COPY /fonts ~/.fonts
COPY /fonts /usr/shared/fonts
COPY /fonts /usr/share/fonts/truetype
# refresh system font cache
RUN fc-cache -f -v
or if you want to install microsoft trueType core fonts. you can do like this
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
# refresh system font cache
RUN fc-cache -f -v
you can use this sample dockerfile too DockerFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With