.NET Core和Docker

If you've got Docker installed you can run a .NET Core sample quickly just like this. Try it:

如果您已安装Docker,则可以像这样快速运行.NET Core示例。 试试吧:

docker run --rm microsoft/dotnet-samples

If your Docker for Windows is in "Windows Container mode" you can try .NET Framework (the 4.x Windows Framework) like this:

如果适用于Windows的Docker处于“ Windows容器模式”,则可以尝试使用.NET Framework(4.x Windows Framework),如下所示:

docker run --rm microsoft/dotnet-framework-samples

I did a video last week with a write up showing how easy it is to get a containerized application into Azure AND cheaply with per-second billing.

上周,录制了一段视频,上面写了一篇文章,展示了将容器化的应用程序轻松地导入Azure并以每秒计费的廉价方式

Container images are easy to share via Docker Hub, the Docker Store, and private Docker registries, such as the Azure Container Registry. Also check out Visual Studio Tools for Docker. It all works very nicely together.

容器映像很容易通过Docker HubDocker Store和私有Docker注册表(例如Azure容器注册表)共享。 另请查看适用于Docker的Visual Studio工具。 所有这些都可以很好地协同工作。

I like this quote from Richard Lander:

我喜欢Richard Lander的话

Imagine five or so years ago someone telling you in a job interview that they care so much about consistency that they always ship the operating system with their app. You probably wouldn’t have hired them. Yet, that’s exactly the model Docker uses!

想象一下,大约5年前,有人在一次求职面试中告诉您,他们非常关心一致性,以至于他们总是随应用程序一起发布操作系统。 您可能不会雇用他们。 但是,这正是Docker使用的模型!

And it's a good model! It gives you guaranteed consistency. "Containers include the application and all of its dependencies. The application executes the same code, regardless of computer, environment or cloud." It's also a good way to make sure your underlying .NET is up to date with security fixes:

这是一个很好的模型! 它为您保证了一致性。 “容器包括应用程序及其所有依赖项。应用程序执行相同的代码,而不管计算机,环境或云如何。” 这也是确保基础.NET具有最新安全修复程序的好方法:

Docker is a game changer for acquiring and using .NET updates. Think back to just a few years ago. You would download the latest .NET Framework as an MSI installer package on Windows and not need to download it again until we shipped the next version. Fast forward to today. We push updated container images to Docker Hub multiple times a month.

Docker是获取和使用.NET更新的游戏改变者。 回想一下几年前。 您可以在Windows上以MSI安装程序包的形式下载最新的.NET Framework,而无需再次下载它,直到我们发布了下一个版本。 快进到今天。 我们每个月多次将更新的容器映像推送到Docker Hub

The .NET images get built using the official Docker images which is nice.

.NET映像是使用官方Docker映像构建的,这很好。

.NET images are built using official images. We build on top of Alpine, Debian, and Ubuntu official images for x64 and ARM. By using official images, we leave the cost and complexity of regularly updating operating system base images and packages like OpenSSL, for example, to the developers that are closest to those technologies. Instead, our build system is configured to automatically build, test and push .NET images whenever the official images that we use are updated. Using that approach, we’re able to offer .NET Core on multiple Linux distros at low cost and release updates to you within hours.

.NET映像是使用官方映像构建的。 我们基于x64和ARM的AlpineDebianUbuntu官方映像构建。 通过使用官方映像,我们可以将定期更新操作系统基本映像和软件包(如OpenSSL)的成本和复杂性留给最接近那些技术的开发人员。 取而代之的是,我们的构建系统配置为每当我们使用的正式映像更新时,就自动构建,测试和推送.NET映像。 使用这种方法,我们可以在多个Linux发行版上以低成本提供.NET Core,并在几个小时内向您发布更新。

Here's where you can find .NET Docker Hub repos:

在这里您可以找到.NET Docker Hub仓库:

.NET Core repos:

.NET Core存储库:

.NET Framework repos:

.NET Framework存储库:

There's a few kinds of images in the microsoft/dotnet repo:

microsoft / dotnet存储库中有几种图像:

  • sdk — .NET Core SDK images, which include the .NET Core CLI, the .NET Core runtime and ASP.NET Core.

    sdk — .NET Core SDK映像,其中包括.NET Core CLI,.NET Core运行时和ASP.NET Core。

  • aspnetcore-runtime — ASP.NET Core images, which include the .NET Core runtime and ASP.NET Core.

    aspnetcore-runtime-ASP.NET Core映像,其中包括.NET Core运行时和ASP.NET Core。

  • runtime — .NET Core runtime images, which include the .NET Core runtime.

    运行时— .NET Core运行时映像,其中包括.NET Core运行时。

  • runtime-deps — .NET Core runtime dependency images, which include only the dependencies of .NET Core and not .NET Core itself. This image is intended for self-contained applications and is only offered for Linux. For Windows, you can use the operating system base image directly for self-contained applications, since all .NET Core dependencies are satisfied by it.

    runtime-deps — .NET Core运行时依赖项映像,其中仅包括.NET Core的依赖项,而不包括.NET Core本身。 该映像用于独立的应用程序,仅适用于Linux。 对于Windows,您可以直接将操作系统基础映像用于独立的应用程序,因为它可以满足所有.NET Core依赖关系。

For example, I'll use an SDK image to build my app, but I'll use aspnetcore-runtime to ship it. No need to ship the SDK with a running app. I want to keep my image sizes as small as possible!

例如,我将使用SDK映像来构建我的应用程序,但是我将使用aspnetcore-runtime来发布它。 无需将SDK与运行中的应用程序一起交付。 我要保持图像尺寸尽可能小

For me, I even made a little PowerShell script (runs on Windows or Linux) that builds and tests my Podcast site (the image tagged podcast:test) within docker. Note the volume mapping? It stores the Test Results outside the container so I can look at them later if I need to.

对我来说,我还送了一个小PowerShell脚本(在Windows或Linux上运行),其构建并测试我的播客网站(图像标记的播客:测试)泊坞窗内。 注意音量映射吗? 它将测试结果存储在容器外部,因此以后可以根据需要查看它们。

#!/usr/local/bin/powershell
docker build --pull --target testrunner -t podcast:test .
docker run --rm -v c:\github\hanselminutes-core\TestResults:/app/hanselminutes.core.tests/TestResults podcast:test

Pretty slick.

很漂亮

Results File: /app/hanselminutes.core.tests/TestResults/_898a406a7ad1_2018-06-28_22_05_04.trx

Total tests: 22. Passed: 22. Failed: 0. Skipped: 0.
Test execution time: 8.9496 Seconds

Go read up on how the .NET Core images are built, managed, and maintained. It made it easy for me to get my podcast site - once dockerized - running on .NET Core on a Raspberry Pi (ARM32).

阅读有关如何构建,管理和维护.NET Core映像的内容。 这对我来说很容易获得我的播客站点-一旦被docker化-在Raspberry Pi(ARM32)的.NET Core上运行

New Sponsor! Never type an invoice again! With DocSight OCR by ActivePDF, you’ll extract data from bills, invoices, PO’s & other documents using zonal data capture technology. Achieve Digital Transformation today!

新赞助商! 永远不要再输入发票! 使用ActivePDF的DocSight OCR ,您将使用区域数据捕获技术从账单,发票,采购订单和其他文档中提取数据。 今天就实现数字化转型

翻译自: https://www.hanselman.com/blog/net-core-and-docker

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值