Create PDF Files using C# in Docker with IronPDF
IronPDF for .NET Standard now fully supports Docker, including Azure Docker Containers for Linux and Windows.
Docker Containers on Azure in particular enjoyed more permissions than WebApps. This allows rendering of SVG fonts, because system access to GDI+ graphics are enabled.
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
IronPDF on Linux Docker Containers
IronPDF fully supports and is tested on x64 builds, Ubuntu 12+, Debian 8+, and recent CentOS.
IronPDF works 'out-of-the-box' on vanilla docker images, which you can find and learn more about here: https://hub.docker.com/_/microsoft-dotnet-core/
Example DockerFile for Linux
# escape=` FROM mcr.microsoft.com/dotnet/core/runtime:2.1 # Mount folder for an application VOLUME /app WORKDIR /app
Newer .NET Core Runtime Versions
You can also use other versions of .NET Core runtime - for example, this will install an image for .NET hosting with Core 3.1 support.
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 # Mount folder for an application VOLUME /app WORKDIR /app
Linux Package Prerequisites
When we deploy to Linux and Docker, we have to ensure that the instance has the relevant packages installed to support PDF rendering. These packages are often not present in minimalist Linux builds.
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig is set
true, and this will instruct IronPDF to install all needed assets onto your Linux Docker container.
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True
If your application does not have sufficient permissions, you can add the necessary prerequisites manually by adding these RUN ["apt-get"] lines to your Dockerfile. These are normally located at the top, second line, just after the first docker image is defined.
# FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base # After first docker image is defined - install all these dependancies RUN ["apt-get", "update"] RUN ["apt-get", "-y", "install", "libgdiplus"] RUN ["apt-get", "-y", "install", "xvfb", "libfontconfig", "wkhtmltopdf"] RUN ["apt-get", "-y", "install", "libc6-dev"] RUN ["apt-get", "-y", "install", "openssl"] RUN ["apt-get", "-y", "install", "libssl1.0-dev"]
You may also install by hand using
yum or similar - though this is less preferable for Docker.
sudo apt-get update sudo apt-get install -y libgdiplus xvfb libfontconfig wkhtmltopdf libc6-dev openssl libssl1.0-dev
IronPDF Windows Docker Containers
Windows Docker Containers are becoming increaingly 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.
Example DockerFile for Windows
This is an example Windows container Dockerfile for .NET Core 2.1 and .NET 4.0+ applications.
# escape=` FROM mcr.microsoft.com/windows/servercore:ltsc2019 # Create folder for .NET Core installer WORKDIR /dotnet-install # Download .NET Core installer ADD https://download.visualstudio.microsoft.com/download/pr/a431ea89-07d9-4533-9d72-fd246bd2efc7/5bbc08f02800c08b69bce56d03723f18/dotnet-hosting-2.1.17-win.exe dotnet-installer.exe # Execute .NET Core installer USER ContainerAdministrator RUN dotnet-installer.exe /install /quiet /norestart /log dotnet-install.log || exit 0 # Print installation log to the Console USER ContainerUser RUN type dotnet-install.log # Mount application folder VOLUME c:\app
Newer .NET Core Runtime Versions
You can also change the version to .NET 3.1 by changing to the below docker image. Find more at https://hub.docker.com/_/microsoft-dotnet-core/.
# Download .NET Core installer ADD https://download.visualstudio.microsoft.com/download/pr/ff658e5a-c017-4a63-9ffe-e53865963848/15875eef1f0b8e25974846e4a4518135/dotnet-hosting-3.1.3-win.exe dotnet-installer.exe
IronPDF + Docker Cloud Hosting
IronPDF within Docker containers can easily be deployed to cloud platforms including Amazon AWS, Heroku, Azure, Digital Ocean and many more.