Setting up IronOCR in Docker Containers

This article was translated from English: Does it need improvement?
Translated
View the article in English

Want to OCR Images or Pdf Files in C#?

IronOCR now fully supports Docker, including Azure Docker Containers for Linux and Windows.

Docker Linux AWS 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.

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

  • 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.

Install-Package IronOcr

Ubuntu Linux DockerFiles

Docker Linux Ubuntu

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

Docker Linux Debian

Debian 11 with .NET 5

# Use the base runtime image for Debian 10 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 10 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 10 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 10 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"]

Preguntas Frecuentes

¿Cómo puedo desplegar aplicaciones OCR de C# en contenedores Docker?

Puedes implementar aplicaciones de OCR en C# en contenedores Docker utilizando IronOCR, una biblioteca de OCR en C# que se integra con Docker. Deberás configurar los contenedores Docker con los paquetes necesarios como apt-utils, libgdiplus y libc6-dev, y usar las imágenes oficiales de Docker de Microsoft para un rendimiento óptimo.

¿Qué sistemas operativos son mejores para ejecutar IronOCR en Docker?

Para ejecutar IronOCR en Docker, se recomienda utilizar las últimas distribuciones de Linux de 64 bits como Ubuntu 20, Ubuntu 18, Debian 11 y Debian 10, ya que ofrecen fácil configuración y soporte.

¿Cómo configuro IronOCR en contenedores Docker de Azure?

Para configurar IronOCR en contenedores Docker de Azure, seguirías los mismos pasos que para otros entornos Docker. Usa el paquete NuGet de IronOcr, configura las distribuciones de Linux recomendadas, y asegúrate de que todas las dependencias necesarias estén incluidas en tu Dockerfile.

¿Cuáles son los pasos para configurar IronOCR usando .NET 5 en Docker?

Para configurar IronOCR utilizando .NET 5 en Docker, necesitas crear un Dockerfile que instale el paquete NuGet IronOcr, añada paquetes requeridos como apt-utils y libgdiplus, y utilice las imágenes oficiales de Docker de .NET 5 de Microsoft como imagen base.

¿Puede IronOCR usarse en entornos Docker en Windows?

Sí, IronOCR puede usarse en entornos Docker en Windows. El proceso implica usar el paquete NuGet de IronOcr y configurar el Dockerfile para incluir las dependencias necesarias y configuraciones específicas para sistemas operativos Windows.

¿Cuáles son los beneficios de usar Docker para alojar aplicaciones OCR de .NET?

Usar Docker para alojar aplicaciones OCR de .NET permite una fácil implementación, mejor gestión de recursos y mayor portabilidad entre diferentes entornos. Los contenedores Docker son autosuficientes, asegurando que las aplicaciones se ejecuten de manera consistente sin importar dónde se desplieguen.

¿Se requiere configuración manual para distribuciones de Linux no recomendadas en Docker?

Sí, si estás utilizando distribuciones de Linux diferentes a las recomendadas (Ubuntu 20, Ubuntu 18, Debian 11, Debian 10), es posible que debas realizar configuraciones manuales utilizando apt-get. La guía sobre la configuración manual está disponible en la guía 'Configuración Manual de Linux' proporcionada por IronOCR.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado