her*_*gth 4 docker .net-core dockerfile asp.net-core
在 Visual Studio 中,我创建了一个默认的 ASP.NET Core Web 应用程序,并启用了 Docker 支持。
它使用Linux 容器的默认Microsoft 官方映像。
这是我的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"]
Run Code Online (Sandbox Code Playgroud)
我想在其上安装Microsoft Windows 字体,我尝试了以下操作但它不起作用:
RUN apt install ttf-mscorefonts-installer
Run Code Online (Sandbox Code Playgroud)
如何在此容器上安装字体?
STL*_*STL 10
知道了。修改 Dockerfile 的开头,如下所示:
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
[...]
Run Code Online (Sandbox Code Playgroud)
第一行更新Linux 操作系统中的默认/etc/apt/sources.list文件以包含“contrib”存档区域(这是ttf-mscorefonts-installer所在的位置)。这确保 apt-get 可以找到它并在第二行中正常安装它(以及你也需要的 fontconfig 。)
作为记录,此页面建议使用“fonts-liberation”包而不是 ttf-mscorefonts-installer,您也可以在 Dockerfile 的开头使用两个不同的行,如下所示:
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
[...]
Run Code Online (Sandbox Code Playgroud)
Aph*_*ze_ 10
以下是我对基于 Debian 12 的 mcr.microsoft.com/dotnet/aspnet:8.0-preview 的操作方法:
RUN echo "deb http://deb.debian.org/debian/ bookworm main contrib" > /etc/apt/sources.list && \
echo "deb-src http://deb.debian.org/debian/ bookworm main contrib" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/ bookworm-security main contrib" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/ bookworm-security main contrib" >> /etc/apt/sources.list
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
Run Code Online (Sandbox Code Playgroud)
您可以将自定义字体复制到 docker 映像并像这样安装字体
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
Run Code Online (Sandbox Code Playgroud)
或者如果您想安装 microsoft trueType 核心字体。你可以这样做
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
Run Code Online (Sandbox Code Playgroud)
你也可以使用这个示例 dockerfile
| 归档时间: |
|
| 查看次数: |
4484 次 |
| 最近记录: |