Method 1 (multi-stage build)
It's better to copy fonts from mcr.microsoft.com/windows image to mcr.microsoft.com/windows/servercore or whichever base image you would like to use. Since it is shipped with most of the fonts & it supports most of the asian fonts as well.
Below three things need to be copied from mcr.microsoft.com/windows image.
- Fonts from C:\Windows\Fonts (we need to exclude lucon.ttf while copying since it will be present in most of the windows container images by default)
- Export 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' registry
- Export 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink' registry (for some scenarios we need FontLink's as well, so its better to include this registry)
I used multistage dockerfile to copy those.
# stage-1
FROM mcr.microsoft.com/windows:1809 AS fullWindows
# Copy below stuff
RUN powershell -NoProfile -Command "\
Copy-Item -Path C:\Windows\Fonts -Exclude lucon.ttf -Destination c:\Fonts -Recurse; \
New-Item -ItemType Directory -Force -Path c:\registries; \
reg export 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' c:\registries\FontsReg.reg ; \
reg export 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink' c:\registries\FontLink.reg ; \
# stage-2 (final build)
FROM mcr.microsoft.com/windows/servercore:1809
# Take font from above image, exclude lucon.ttf, as it exists in image already
COPY --from=fullWindows /Fonts/ /Windows/Fonts/
COPY --from=fullWindows /registries/ ./registries/
# Import the font registries.
RUN powershell -NoProfile -Command "\
reg import C:\registries\FontsReg.reg; \
reg import C:\registries\FontLink.reg; \
"
# Copy your code
COPY your-code ./your-code/
ENTRYPOINT C:/your-code/your-app.exe
If you copy all fonts as mentioned above it will add more than 300MB to your final docker image.
Method 2
If you prefer not to use multi-stage builds in your pipeline or need to copy only a few selected fonts, you can go ahead with the approach below as mentioned by other answers. 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.
lucon.ttf which is present by default does not support asian languages. In the below example i would add support for chinese, korean & japanese fonts.
I will copy malgun.ttf, msgothic.ttc & simsun.ttc fonts which support most of the chinese, korean & japanese characters to the Fonts folder in the docker build context.
I will add FontLink for GenericMonospace fontStyle. Change this accordingly if you want to support other styles such as Arial etc...
FROM mcr.microsoft.com/windows/servercore:1809
# Copy fonts
COPY Fonts ./Windows/Fonts
# Register the Fonts.
RUN powershell.exe -NoProfile -Command New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' -Name 'SimSun "&" NSimSun (TrueType)' -PropertyType String -Value simsun.ttc
RUN powershell.exe -NoProfile -Command New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' -Name 'Malgun Gothic (TrueType)' -PropertyType String -Value malgun.ttf
RUN powershell.exe -NoProfile -Command New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' -Name 'MS Gothic "&" MS UI Gothic "&" MS PGothic (TrueType)' -PropertyType String -Value msgothic.ttc
# Register the FontLink
RUN powershell.exe -NoProfile -Command New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink' -Name 'SimSun' -PropertyType MultiString -Value ('MSGOTHIC.TTC,MS UI Gothic','SIMSUN.TTC,SimSun','MALGUN.TTF,Malgun Gothic')
# Copy your code
COPY your-code ./your-code/
ENTRYPOINT C:/your-code/your-app.exe