[英]Which libraries should I install for work with System.Drawing.Common in ASP NET Core application inside Alpine-based image
I have the following code in dotnet core 3.0 application:我在 dotnet core 3.0 应用程序中有以下代码:
...
// This url returns image (Content-Type: Blob)
var imageUrl = "https://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96";
HttpClient client = HttpClientFactory.Create();
using (var input = await client.GetStreamAsync(imageUrl))
{
var bitmap = new Bitmap(input); // this is dangerous code
}
...
I want to run this code inside docker container, which based on alpine3.9 (mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9) I know that I should install additional libraries inside docker container for working with System.Drawing.Common:我想在 docker 容器中运行此代码,该容器基于 alpine3.9 (mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9) 我知道我应该在 docker 容器中安装其他库才能工作使用 System.Drawing.Common:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk update \
&& apk add \
libgdiplus
But anyway - it fails with the following stacktrace:但无论如何 - 它失败了以下堆栈跟踪:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Bitmap..ctor(Stream stream)
I know that this code works fine inside debian-based container which I cook like this:我知道这段代码在我这样烹制的基于 debian 的容器中运行良好:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libgdiplus
I tried to install libgdiplus-dev
, fontconfig
and ttf-dejavu
libraries inside alpine container but it doesn't works我试图在 alpine 容器中安装libgdiplus-dev
、 fontconfig
和ttf-dejavu
库,但它不起作用
So the main question - is it libraries related issue or bug inside dotnet?所以主要问题 - 是与库相关的问题还是 dotnet 中的错误? If first - what libraries should I install for this to work?如果首先 - 我应该安装哪些库才能使其工作?
TL;DR TL;博士
change https://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96
to https://www.scandit.com/wp-content/themes/scandit/barcode-generator.php?symbology=code128&value=213214214&size=200&ec=L
将https://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96
更改为https://www.scandit.com/wp-content/themes/scandit/barcode-generator.php?symbology=code128&value=213214214&size=200&ec=L
DESCRIPTION描述
It is bug inside dotnet - https://github.com/dotnet/corefx/issues/41527 Issue link generates GIF - it causes issue.这是 dotnet 内部的错误 - https://github.com/dotnet/corefx/issues/41527问题链接生成 GIF - 它会导致问题。 Workaround - use link which will generates JPEG解决方法 - 使用将生成 JPEG 的链接
For me the following modification of dockerfile worked (.net core 3.1).对我来说,dockerfile 的以下修改有效(.net core 3.1)。 Pay attention that libgdiplus, libc-dev and libx11-dev are added to the runtime:注意 libgdiplus、libc-dev 和 libx11-dev 添加到运行时:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine3.12 as builder
WORKDIR /app
COPY nuget.config nuget.config
RUN apk update
RUN apk add --update nodejs nodejs-npm
RUN cd XXX.XXXXXXX.YYYYYY && dotnet restore --configfile ../nuget.config &&
dotnet publish -c Release -o ../out/
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine3.12
WORKDIR /app
# Alpine 3.x Docker images no longer have tzdata package
RUN apk update && \
apk add --no-cache tzdata
RUN apk add libgdiplus --repository https://dl-3.alpinelinux.org/alpine/edge/testing/
RUN apk add libc-dev libx11-dev
COPY --from=builder /app/out .
CMD ["dotnet", "XXX.XXXXXXX.YYYYYY"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.