ZEIT现在使用Docker部署开源ASP.NET Core Web应用程序

ZEIT is a new cloud service and "now" is the name of their deployment tool. ZEIT World is their DNS service. If you head over to https://zeit.co/ you'll see a somewhat cryptic animated gif that shows how almost impossibly simple it is to deploy a web app with ZEIT now.

ZEIT是一项新的云服务,“ now ”是其部署工具的名称。 ZEIT World是他们的DNS服务。 如果转到https://zeit.co/,您将看到一个有点神秘的gif动画,它显示了现在使用ZEIT部署Web应用程序几乎是不可能的。

ZEIT works with .NET Core and ASP.NET

You can make a folder, put an index.html (for example) in it and just run "now." You'll automatically get a website with an autogenerated name and it'll be live. It's probably the fastest and easiest deploy I've ever seen. Remember when Heroku (then Azure, then literally everyone) started using git for deployment? Clearly being able to type "now" and just get a web site on the public internet was the next step. (Next someone will make "up" which will then get replaced with just pressing ENTER on an empty line! ;) )

您可以创建一个文件夹,在其中放入index.html(例如),然后运行“ now” 。 您会自动获得一个带有自动生成名称的网站,并且该网站将上线。 这可能是我见过的最快,最简单的部署。 还记得Heroku(然后是Azure,然后是每个人)何时开始使用git进行部署吗? 显然,下一步就是要输入“ now”,然后在公共互联网上获得一个网站。 (接下来,有人将制作“ up”,然后只需在空行上按ENTER即可替换它!))

Jokes aside, now is clean and easy. I appreciate their organizational willpower to make an elegant and simple command line tool. I suspect it's harder than it looks to keep things simple.

除了笑话,现在很简单。 我感谢他们的组织能力,使他们能够制作出优雅而简单的命令行工具。 我怀疑这很难使事情变得简单。

All of their examples use JavaScript and node.js, but they also support Docker, which means they support open source ASP.NET Core on .NET Core! But do they know they do? ;) Let's find out.

他们所有的示例都使用JavaScript和node.js,但它们还支持Docker,这意味着它们支持.NET Core上的开源ASP.NET Core ! 但是他们知道吗? ;)让我们找出答案。

And more importantly, how easy is it? Can I take a site from concept to production in minutes? Darn tootin' I can.

更重要的是,这有多容易? 我可以在几分钟内将一个站点从概念变成生产吗? 我该死。

First, make a quick ASP.NET Core app. I'll use the MVC template with Bootstrap.

首先,制作一个快速的ASP.NET Core应用程序。 我将在Bootstrap中使用MVC模板。

C:\Users\scott\zeitdotnet>dotnet new mvc
Content generation time: 419.5337 ms
The template "ASP.NET Core Web App" created successfully.

I'll do a quick dotnet restore to get the packages for my project.

我将快速进行dotnet还原,以获取项目的软件包。

C:\Users\scott\zeitdotnet>dotnet restore
Restoring packages for C:\Users\scott\zeitdotnet\zeitdotnet.csproj...
Generating MSBuild file C:\Users\scott\zeitdotnet\obj\zeitdotnet.csproj.nuget.g.props.
Generating MSBuild file C:\Users\scott\zeitdotnet\obj\zeitdotnet.csproj.nuget.g.targets.
Writing lock file to disk. Path: C:\Users\scott\zeitdotnet\obj\project.assets.json
Restore completed in 2.93 sec for C:\Users\scott\zeitdotnet\zeitdotnet.csproj.

NuGet Config files used:
C:\Users\scott\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
https://api.nuget.org/v3/index.json
C:\LocalNuGet
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Now I need to add a Dockerfile. I'll make one in the root that looks like this:

现在,我需要添加一个Dockerfile。 我将在如下所示的根目录中创建一个:

FROM microsoft/aspnetcore
LABEL name="zeitdotnet"
ENTRYPOINT ["dotnet", "zeitdotnet.dll"]
ARG source=.
WORKDIR /app
EXPOSE 80
COPY $source .

Note that I could have ZEIT build my app for me if I used the aspnetcore Dockerfile that includes the .NET Core SDK, but that would not only make my deployment longer, it would also make my docker images a LOT larger. I want to include JUST the .NET Core runtime in my image, so I'll build and publish locally.

请注意,如果我使用包含.NET Core SDK的aspnetcore Dockerfile,则可以让ZEIT为我构建应用程序,但这不仅会使我的部署更长,而且还会使我的Docker映像变大。 我只想在映像中包括.NET Core运行时,所以我将在本地构建和发布。

ZEIT now is going to need to see my Dockerfile, and since I want my app to include the binaries (I don't want to ship my source in the Docker image up to ZEIT) I need to mark my Dockerfile as "Content" and make sure it's copied to the publish folder when my app is built and published.

ZEIT现在将需要查看我的Dockerfile,并且由于我希望我的应用程序包含二进制文件(我不想将我的源代码在Docker映像中提供给ZEIT),因此我需要将Dockerfile标记为“ Content”,然后确保在构建和发布我的应用时将其复制到发布文件夹。

<ItemGroup>
  <None Remove="Dockerfile" />
</ItemGroup>

<ItemGroup>
  <Content Include="Dockerfile">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

I'll add this my project's csproj file. If I was using Visual Studio, this is the 
same as right clicking on the Properties of the Dockerfile, setting it to Content and then "Always Copy to Output Directory." 右键单击Dockerfile的“属性”,将其设置为“内容”,然后“始终复制到输出目录”相同。

Now I'll just build and publish to a folder with one command:

现在,我将使用一个命令来构建并发布到一个文件夹:

C:\Users\scott\zeitdotnet>dotnet publish
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

zeitdotnet -> C:\Users\scott\zeitdotnet\bin\Debug\netcoreapp1.1\zeitdotnet.dll

And finally, from the .\bin\Debug\netcoreapp1.1\ folder I run "now." (Note that I've installed now and signed up for their service, of course.)

最后,从。\ bin \ Debug \ netcoreapp1.1 \文件夹运行“ now”。 (请注意,我现在已经安装并注册了他们的服务。)

C:\Users\scott\zeitdotnet\bin\Debug\netcoreapp1.1\publish>now
> Deploying ~\zeitdotnet\bin\Debug\netcoreapp1.1\publish
> Ready! https://zeitdotnet-gmhcxevqkf.now.sh (copied to clipboard) [3s]
> Upload [====================] 100% 0.0s
> Sync complete (196.18kB) [2s]
> Initializing…
> Building
> ▲ docker build
> ---> 035a0a1401c3
> Removing intermediate container 289b9e4ce5d9
> Step 6 : EXPOSE 80
> ---> Running in efb817308333
> ---> fbac2aaa3039
> Removing intermediate container efb817308333
> Step 7 : COPY $source .
> ---> ff009cfc48ea
> Removing intermediate container 8d650c1867cd
> Successfully built ff009cfc48ea
> ▲ Storing image
> ▲ Deploying image
> Deployment complete!

Now has put the generated URL in my clipboard (during deployment you'll get redirected to a lovely status page) and when it's deployed I can visit my live site. But, that URL is not what I want. I want to use a custom URL.

现在,将生成的URL放在剪贴板中(在部署过程中,您将被重定向到一个可爱的状态页面),并且在部署后,我可以访问我的实时站点。 但是,该URL不是我想要的。 我想使用自定义网址。

I can take one of my domains and set it up with ZEIT World's DNS but I like DNSimple (ref).

我可以选择一个域,并使用ZEIT World的DNS进行设置,但我喜欢DNSimple (ref)。

I can add my domain as an external one after adding a TXT record to my DNS to verify I own it. Then I setup a CNAME to point my subdomain to alias.zeit.co.

在向我的DNS添加TXT记录以确认我拥有它之后,我可以将我的域添加为外部域。 然后,我设置一个CNAME以将我的子域指向alias.zeit.co。

C:\Users\scott\Desktop\zeitdotnet>now alias https://zeitdotnet-gmhcxevqkf.now.sh http://zeitdotnet.hanselman.com
> zeitdotnet.hanselman.com is a custom domain.
> Verifying the DNS settings for zeitdotnet.hanselman.com (see https://zeit.world for help)
> Verification OK!
> Provisioning certificate for zeitdotnet.hanselman.com
> Success! Alias created:
https://zeitdotnet.hanselman.com now points to https://zeitdotnet-gmhcxevqkf.now.sh [copied to clipboard]

And that's it. It even has a nice SSL certificate that they applied for me. It doesn't terminate to SSL all the way into the docker container's Kestral web server, but for most things that aren't banking it'll be just fine.

就是这样。 他们甚至为我申请了一个不错的SSL证书。 它不会一直终止到Docker容器的Kestral Web服务器中的SSL,但是对于大多数不进行银行业务的事情来说,这会很好。

All in all, a lovely experience. Here's my Hello World ASP.NE Core app running in ZEIT and deployed with now  at http://zeitdotnet.hanselman.com (if you are visiting this long after this was published, this sample MAY be gone.)

总而言之,一个愉快的经历。 这是我的Hello World ASP.NE Core应用程序,该应用程序在ZEIT中运行,并已在http://zeitdotnet.hanselman.com上进行了部署(如果在发布此书后访问了这么长时间,此示例可能会消失。)

I am still learning about this (this whole exercise was about 30 total minutes and asking Glenn Condron a docker question) so I'm not clear how this would work in a large multi-container deployment, but as long as your site is immutable (don't write to the container's local disk!) ZEIT says it will scale your single containers. Perhaps docker-compose support is coming?

我仍在学习有关此内容(整个练习大约需要30分钟,并向Glenn Condron询问docker问题),因此我不清楚这在大型多容器部署中如何工作,但前提是您的网站是不变的(不要写到容器的本地磁盘!)ZEIT说它将扩展您的单个容器。 也许docker-compose支持即将到来?

翻译自: https://www.hanselman.com/blog/zeit-now-deployments-of-open-source-aspnet-core-web-apps-with-docker

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值