Setting up IronBarcode in Docker Containers

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

IronBarcode 完全支持 Docker,包括用于 Linux 和 Windows 的 Azure 和 AWS 中的容器。

class="main-content__small-images-inline"> Docker Azure Linux Amazon Windows

为什么使用 Docker?

Docker 使开发人员能够轻松地将任何应用程序打包、发布和运行为轻量级、可移植、自给自足的容器,并且可以在几乎任何地方运行。

IronBarcode 和 Linux 入门

如果 Docker 和 .NET 对你来说是新的,我们推荐这篇优秀文章,它介绍了在 Visual Studio 项目中设置 Docker 调试和集成。

对于在 Linux 上使用 IronBarcode,我们也强烈推荐阅读我们的IronBarcode Linux 设置和兼容性指南

推荐的 Linux Docker 发行版

我们推荐使用以下 64 位 Linux 发行版,以便在配置 IronBarcode 时减少麻烦:

  • Ubuntu ≥18
  • Debian ≥10
  • CentOS ≥7

我们推荐使用微软的官方 Docker 镜像。 其他 Linux 发行版部分支持,但可能需要手动配置和依赖项安装。 查看我们的Linux 手动设置指南,了解如何在 Linux 上设置更多信息。

IronBarcode Linux Docker 安装要点

使用我们的 NuGet 包

我们推荐使用IronBarCode NuGet 包—在 Windows、macOS 和 Linux 上开发时无缝运行。

Install-Package BarCode

Ubuntu Linux Dockerfiles

class="main-content__small-images-inline"> Docker Ubuntu

Ubuntu 22 with .NET 7

# Base runtime image (Ubuntu 22 with .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (Ubuntu 22 with .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy 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

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

Ubuntu 22 with .NET 6 (LTS)

# Base runtime image (Ubuntu 22 with .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:6.0-jammy AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (Ubuntu 22 with .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy 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

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

Ubuntu 20 with .NET 6 (LTS)

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

# Install necessary packages
RUN apt update

# Base development image (Ubuntu 20 with .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:6.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

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

Ubuntu 20 with .NET 5

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

# Install necessary packages
RUN apt update

# Base development image (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 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

# Final image to run the 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 with .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:3.1-focal AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (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 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

# Final image to run the 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 with .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:3.1-bionic AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (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 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

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

Debian Linux DockerFiles

Debian 11 with .NET 7

# Base runtime image (Debian 11 with ASP.NET Core Runtime)
FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (Debian 11 with .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim 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

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

Debian 11 with .NET 6 (LTS)

# Base runtime image (Debian 11 with ASP.NET Core Runtime)
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (Debian 11 with .NET SDK)
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim 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

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

Debian 11 with .NET 5

# Base runtime image (Debian 11 with ASP.NET Core Runtime)
FROM mcr.microsoft.com/dotnet/aspnet:5.0-bullseye-slim AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (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 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

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

Debian 11 with .NET 3.1 LTS

# Base runtime image (Debian 11 with ASP.NET Core Runtime)
FROM mcr.microsoft.com/dotnet/aspnet:3.1-bullseye-slim AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (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 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

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

Debian 10 with .NET 5

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

# Install necessary packages
RUN apt update

# Base development image (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 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

# Final image to run the 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 with .NET runtime)
FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base
WORKDIR /app

# Install necessary packages
RUN apt update

# Base development image (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 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

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

CentOS 7 with .NET 7

# Base runtime image (CentOS 7)
FROM centos:7 as base

# Install necessary packages
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum install -y dotnet-runtime-7.0
WORKDIR /app

# Build SDK image (CentOS 7)
FROM centos:7 as build

# Install necessary packages
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum install -y dotnet-sdk-7.0

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

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

CentOS 7 with .NET 6 (LTS)

# Base runtime image (CentOS 7)
FROM centos:7 as base

# Install necessary packages
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum install -y dotnet-runtime-6.0
WORKDIR /app

# Build SDK image (CentOS 7)
FROM centos:7 as build

# Install necessary packages
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum install -y dotnet-sdk-6.0

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

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

CentOS 7 with .NET 3.1 LTS

# Base runtime image (CentOS 7)
FROM centos:7 AS base

# Install necessary packages
RUN yum install sudo -y
RUN sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN sudo yum install aspnetcore-runtime-3.1 -y

WORKDIR /app
EXPOSE 80
EXPOSE 443

# Build SDK image (CentOS 7)
FROM centos:7 AS build

# Install necessary packages
RUN yum install sudo -y
RUN sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN sudo yum install dotnet-sdk-3.1 -y

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

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

常见问题解答

如何在Linux的Docker中设置条码应用程序?

要在Linux的Docker中设置条码应用程序,可以使用IronBarcode。从拉取合适的.NET Docker映像开始,使用dotnet add package IronBarcode安装IronBarcode NuGet包,并配置Dockerfile以在容器中构建和运行应用程序。

哪些Linux发行版最适合运行带有条码应用程序的Docker?

推荐的Linux发行版是Ubuntu ≥18、Debian ≥10和CentOS ≥7,因为它们易于配置且稳定。

使用Docker进行条码应用程序的好处是什么?

使用Docker进行条码应用程序可以实现容器化,使应用程序更加轻量、便携并在不同环境中保持一致。这对于在Azure和AWS等云服务上部署应用程序尤其有利。

如何解决Docker设置中与条码库相关的问题?

Docker设置中与条码库的常见问题通常可以通过确保所有依赖项正确安装并且Dockerfile正确配置来解决。使用官方Microsoft .NET映像可以帮助简化流程。

我可以在云平台上运行Docker中的条码应用程序吗?

可以,您可以在云平台如Azure和AWS上运行Docker容器中的条码应用程序。IronBarcode支持这些环境,无论是Linux还是Windows。

在Docker容器中安装条码库的过程是什么?

在Docker容器中安装IronBarcode库,方法是使用dotnet add package IronBarcode将IronBarcode NuGet包添加到.NET项目中。

如何确保条码应用程序在不同环境中的兼容性?

为了确保不同环境中的兼容性,使用Docker来容器化您的条码应用程序并通过IronBarCode NuGet包管理依赖项。此方法为应用程序提供一致的环境。

构建条码应用程序的Docker映像推荐使用哪种.NET版本?

建议使用.NET的LTS版本,如.NET 6或3.1,以保证稳定性构建条码应用程序的Docker映像。不过,使用最新版本如.NET 7可以获得最新特性。

IronBarcode 与 .NET 10 兼容吗?我可以在 Linux 系统上的 Docker 容器中使用它吗?

是的。IronBarcode 支持 .NET 10,以及 .NET 9、8、7、6、5、.NET Core、.NET Standard 和 .NET Framework 4.6.2+,并且可以在 Linux 上的 Docker 容器中运行。([ironsoftware.com](https://ironsoftware.com/csharp/barcode/features/compatibility/?utm_source=openai))

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 1,935,276 | 版本: 2025.11 刚刚发布