Setting up IronPDF in Docker Containers

Want to create PDF files in C# ?

IronPDF for .NET Standard now fully supports Docker, including Azure Docker Containers for Linux and Windows.

Why use Docker on Azure?

Alongside excelent enterprise scalability, Docker Containers on Azure enjoyed more permissions than regular WebApps.

This allows rendering of SVG fonts, because system access to GDI+ graphics are enabled.

IronPDF and Linux Primer

If Docker with .NET is new to you, we recommend this excellent article on setting up Docker debugging and integration with Visual Studio projects. https://docs.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2019

We also highly recommend you read of IronPdf Linux Setup and Compatibility Guide

A Short Summary for Busy Developers

We recommend the latest 64 bit Linux OS's below for "zero configuration" setup of IronPDF.

  • Ubuntu 20
  • Ubuntu 18
  • Debian 10 [Currently the Microsoft Azure Default Linux Distro]
  • CentOS 8
  • Amazon AWS Linux 2 [ For Amazon Cloud Hosting ]

We recommend using Microsofts Official Docker Images . Other Linux distros are supported in part, but may require manual configuration using apt-get. See our "Linux Manual Setup" guide

The following deploys a Debian 10 image wiith .NET Core 3.1 LTS

# escape=`
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
# Mount folder for an application
VOLUME /app
WORKDIR /app

Ubuntu Linux DockerFiles

Ubuntu 20 with .NET 5

# base runtime image (Ubuntu 20 w/ .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:5.0-focal AS base
WORKDIR /app

# install necessary packages
RUN apt update \
    && apt install -y sudo libc6 libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 xvfb

# update write permissions
RUN chmod 777 .

# base development image (Ubuntu 20 w/ .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src

# restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"

# build project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build

# publish project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish

# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Ubuntu 20 with .NET 3.1 LTS

# base runtime image (Ubuntu 20 w/ .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:3.1-focal AS base
WORKDIR /app

# install necessary packages
RUN apt update \
    && apt install -y sudo libc6 libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 xvfb

# update write permissions
RUN chmod 777 .

# base development image (Ubuntu 20 w/ .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:3.1-focal AS build
WORKDIR /src

# restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"

# build project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build

# publish project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish

# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Ubuntu 18 with .NET 3.1 LTS

# base runtime image (Ubuntu 18 w/ .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:3.1-bionic AS base
WORKDIR /app

# install necessary packages
RUN apt update \
    && apt install -y sudo libc6 libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 xvfb

# update write permissions
RUN chmod 777 .

# base development image (Ubuntu 18 w/ .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:3.1-bionic AS build
WORKDIR /src

# restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"

# build project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build

# publish project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish

# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Debian Linux DockerFiles

Debian 10 with .NET 5

# base runtime image (Debian 10 w/ .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base
WORKDIR /app

# install necessary packages
RUN apt update \
    && apt install -y sudo libc6 libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 xvfb

# update write permissions
RUN chmod 777 .

# base development image (Debian 10 w/ .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src

# restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"

# build project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build

# publish project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish

# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Debian 10 with .NET 3.1 LTS

#base runtime image (Debian 10 w/ .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base

WORKDIR /app
# install necessary packages

RUN apt update \
    && apt install -y sudo libc6 libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 xvfb

# update write permissions
RUN chmod 777 .

# base development image (Debian 10 w/ .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src

# restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"

# build project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build

# publish project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish

# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

IronPDF Windows Docker Containers

Windows Docker Containers are becoming increasingly popular on Azure, as they give higher levels of performance and scalability, and give developers more permissions to configure instances.

IronPDF will actually perform more attractive text rendering within a Docker container (Windows or Linux) on Azure because of higher levels of access to graphics library and the virtual graphics card.

This article is a really great get-started guide. https://docs.microsoft.com/en-us/visualstudio/containers/overview?view=vs-2019

This is an example Windows container Dockerfile for .NET Core 3.1

# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS baseOS
RUN powershell -Command [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -UseBasicParsing -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -InstallDir '/Program Files/dotnet' -Channel 3.1 -Runtime dotnet; Remove-Item -Force dotnet-install.ps1 && setx /M PATH "%PATH%;C:\Program Files\dotnet"
COPY . .

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base