Setting up IronOCR in Docker Containers
Want to OCR Images or Pdf Files in C#?
IronOCR now fully supports Docker, including Azure Docker Containers for Linux and Windows.
Why use Docker?
Docker enables developers to easily pack, ship, and run any application as a lightweight, portable, self-sufficient container, which can run virtually anywhere.
IronOCR 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 our IronOCR Linux Setup and Compatibility Guide.
Recommended Linux Docker Distributions
We recommend the latest 64-bit Linux OS's below for "easy configuration" of IronOCR.
- Ubuntu 20
- Ubuntu 18
- Debian 11
- Debian 10 [Currently the Microsoft Azure Default Linux Distro]
We recommend using Microsoft's Official Docker Images. Other Linux distros are supported in part, but may require manual configuration using apt-get. See our "Linux Manual Setup" guide.
Working Docker files for Ubuntu and Debian are included in this document:
IronOCR Linux Docker Installation Essentials
Use Our NuGet Package
We recommend using the IronOCR NuGet Package. It works when developing on Windows, macOS, and Linux.
Ubuntu Linux DockerFiles
Ubuntu 20 with .NET 5
# Use the base runtime image for Ubuntu 20 with .NET runtime
FROM mcr.microsoft.com/dotnet/runtime:5.0-focal AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Ubuntu 20 with .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 the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Ubuntu 20 with .NET 3.1 LTS
# Use the base runtime image for Ubuntu 20 with .NET runtime
FROM mcr.microsoft.com/dotnet/runtime:3.1-focal AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Ubuntu 20 with .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 the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Ubuntu 18 with .NET 3.1 LTS
# Use the base runtime image for Ubuntu 18 with .NET runtime
FROM mcr.microsoft.com/dotnet/runtime:3.1-bionic AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Ubuntu 18 with .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 the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Debian Linux DockerFiles
Debian 11 with .NET 5
# Use the base runtime image for Debian 11 with .NET runtime
FROM mcr.microsoft.com/dotnet/aspnet:5.0-bullseye-slim AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Debian 11 with .NET SDK
FROM mcr.microsoft.com/dotnet/sdk:5.0-bullseye-slim AS build
WORKDIR /src
# Restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"
# Build the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Debian 11 with .NET 3.1 LTS
# Use the base runtime image for Debian 11 with .NET runtime
FROM mcr.microsoft.com/dotnet/aspnet:3.1-bullseye-slim AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Debian 11 with .NET SDK
FROM mcr.microsoft.com/dotnet/sdk:3.1-bullseye-slim AS build
WORKDIR /src
# Restore NuGet packages
COPY ["Example/Example.csproj", "Example/"]
RUN dotnet restore "Example/Example.csproj"
# Build the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Debian 10 with .NET 5
# Use the base runtime image for Debian 10 with .NET runtime
FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Debian 10 with .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 the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Debian 10 with .NET 3.1 LTS
# Use the base runtime image for Debian 10 with .NET runtime
FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base
WORKDIR /app
# Install necessary packages
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
# Use the base development image for Debian 10 with .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 the project
COPY . .
WORKDIR "/src/Example"
RUN dotnet build "Example.csproj" -c Release -o /app/build
# Publish the project
FROM build AS publish
RUN dotnet publish "Example.csproj" -c Release -o /app/publish
# Run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]
Frequently Asked Questions
What is IronOCR and how does it work with Docker?
IronOCR is an advanced OCR library for .NET that now fully supports Docker containers. This enables the execution of OCR applications in a scalable, portable, and consistent environment across various platforms like Linux, Windows, and macOS using Docker.
Why should I use Docker for my OCR applications?
Docker allows developers to package, ship, and run applications as lightweight, portable, and self-sufficient containers. This means OCR applications can run consistently in any environment, simplifying deployment and development processes.
Can I use IronOCR in a Linux-based Docker container?
Yes, IronOCR is designed to work seamlessly within Linux-based Docker containers. The documentation provides Docker files for popular Linux distributions like Ubuntu and Debian to ensure easy integration.
Which Linux distributions are recommended for running IronOCR in Docker?
IronOCR recommends using 64-bit versions of Ubuntu 20, Ubuntu 18, Debian 11, and Debian 10. These distributions offer straightforward configuration, although other distributions may require manual setup.
How do I install IronOCR in a Docker container?
You can install IronOCR in a Docker container by using its NuGet package. The setup involves creating Docker files for your specific environment and setting up dependencies using the `apt-get` package manager.
Is IronOCR compatible with different versions of the .NET runtime?
Yes, IronOCR supports various .NET runtimes including .NET 5 and .NET 3.1 LTS, as demonstrated in the Docker files provided in the documentation for both Ubuntu and Debian distributions.
What are the necessary packages required for running IronOCR in Docker?
To run IronOCR in a Docker environment, essential packages like `apt-utils`, `libgdiplus`, and `libc6-dev` need to be installed. These dependencies are crucial for the proper operation of .NET applications that utilize IronOCR.
Can I use IronOCR with Azure Docker Containers?
Yes, IronOCR is fully compatible with Azure Docker Containers, allowing you to deploy and run .NET OCR applications on both Linux and Windows platforms within the Azure ecosystem.
What is the best way to develop and debug Docker applications using IronOCR?
For those new to Docker with .NET, the documentation recommends resources from Microsoft on setting up Docker debugging and integration with Visual Studio projects. This approach facilitates a smoother development experience.
Are there any official Docker images recommended for IronOCR?
IronOCR recommends using Microsoft's Official Docker Images for running .NET applications. These images are designed to provide a high level of compatibility and performance for .NET-based applications.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.