在 Docker 容器中设置 IronBarCode

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

想要 使用 C# 阅读/生成条形码?

IronBarCode 现在完全支持 Docker,包括 Linux 和 Windows 的 Azure Docker Containers。

Docker Azure Linux 亚马逊 Windows

为什么使用 Docker?

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

IronBarCode 和 Linux 入门

如果您对 Docker 与 .NET 的结合还不熟悉,我们向您推荐这篇关于设置 Docker 调试和与 Visual Studio 项目集成的优秀文章。 https://docs.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2019

我们还强烈建议您阅读我们的 IronBarCode Linux 安装和兼容性指南

推荐的 Linux Docker 发行版

我们推荐使用以下最新的 64 位 Linux 操作系统,以便 "轻松配置 "IronBarCode。

  • 乌班图 22
  • 乌班图 20
  • 乌班图 18
  • Debian 11
  • Debian 10 [目前,Microsoft Azure 默认 Linux Distro]
  • CentOS 7

我们建议使用微软的 官方 Docker 映像 .部分支持其他 Linux 发行版,但可能需要使用 apt-get 手动配置。请参阅我们的"Linux 手动设置"指南

本文档包含适用于 Ubuntu 和 Debian 的 Docker 工作文件:

IronBarCode Linux Docker 安装要点

使用我们的 NuGet 软件包

我们建议使用 铁杆代码 NuGet 软件包可在 Windows、macOS 和 Linux 上进行开发。

Install-Package BarCode

Ubuntu Linux DockerFiles

Docker 乌班图

Ubuntu 22 与 .NET 7

# base runtime image (Ubuntu 22 w/ .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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Ubuntu 22 与 .NET 6 (LTS)

# base runtime image (Ubuntu 22 w/ .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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

配备 .NET 6 (LTS) 的 Ubuntu 20

# base runtime image (Ubuntu 20 w/ .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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Ubuntu 20 与 .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

# 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"]

配备 .NET 3.1 LTS 的 Ubuntu 20

# 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

# 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 与 .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

# 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 11 与 .NET 7

# base runtime image (Debian 11 w/ 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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

配备 .NET 6 (LTS) 的 Debian 11

# base runtime image (Debian 11 w/ 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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

配备 .NET 5 的 Debian 11

# base runtime image (Debian 11 w/ 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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

配备 .NET 3.1 LTS 的 Debian 11

# base runtime image (Debian 11 w/ 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 w/ .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

Debian 10 与 .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

# 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"]

配备 .NET 3.1 LTS 的 Debian 10

# 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

# 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"]

CentOS 7 与 .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

CentOS 7 与 .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]

CentOS 7 与 .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
# run app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Example.dll"]