使用Docker,Kitematic,VirtualBox,Azure,ASP.NET和Visual Studio集思广益的开发工作流

First, a disclaimer. I have no idea what I'm talking about. I'm learning and exploring some ideas, and I wanted to see what the development process looks like today (December 2015) with Docker, ASP.NET, and Visual Studio on my Windows 10 machine. I'm also interested in your ideas in the comments, and I'll share them directly with the folks who are working on making Docker integration with Visual Studio.

首先,免责声明。 我不知道我在说什么。 我正在学习和探索一些想法,我想看看今天(2015年12月)在Windows 10计算机上使用Docker,ASP.NET和Visual Studio的开发过程是什么样的。 我也对您在评论中的想法感兴趣,并将与正在与Docker集成到Visual Studio的人们直接分享这些想法。

This post uses the bits and stuff and hacks that are working today. Some of this is alpha, some is hacky, but it's all very interesting. What do you think?

这篇文章使用了今天有用的零碎东西和技巧。 其中有些是Alpha,有些是hacky,但这都很有趣。 你怎么看?

在Windows上设置Docker (Setting up Docker on Windows)

I got a new laptop and needed to set it up. This seemed like a good to time re-discover Docker on Windows.

我有一台新笔记本电脑,需要进行设置。 在Windows上重新发现Docker似乎是个不错的时机。

  • For this ASP.NET-centric example, I'm assuming you have Windows with Visual Studio, but you can get Visual Studio 2015 Community for free if you need it. You'll want ASP.NET 5 RC1 as well.

    对于此以ASP.NET为中心的示例,我假设您具有带Visual Studio的Windows,但是如果需要,可以免费获得Visual Studio 2015社区。 您还将需要ASP.NET 5 RC1

  • Go to https://www.docker.com, click Get Started, then Windows. You'll end up here: http://docs.docker.com/windows/started/.

    转到https://www.docker.com ,单击“入门”,然后单击Windows。 您将在这里结束: http : //docs.docker.com/windows/started/

    • Note, you'll need hardware virtualization enabled in your systems BIOs, and if you are already running HyperV, either turn it off (I just to go Windows Features and uncheck it. It can be quickly turned back on later) or create a boot menu to switch between Hyper-V and VirtualBox.

      请注意,您需要在系统BIO中启用硬件虚拟化,并且如果您已经在运行HyperV,则可以将其关闭(我只是打开Windows功能并取消选中它。稍后可以快速将其重新打开)或创建启动菜单可在Hyper-V和VirtualBox之间切换。

    • The Docker website could get to the point faster, but they are making sure you're prepped for success.

      Docker网站可以更快地达到目标,但是他们可以确保您为成功做好了准备。

    Go to https://www.docker.com, click Get Started, then Windows. You'll end up here: http://docs.docker.com/windows/started/.

    转到https://www.docker.com ,单击“入门”,然后单击Windows。 您将在这里结束: http : //docs.docker.com/windows/started/

  • Download Docker Toolbox which has a great chained installer that includes:

    下载Docker Toolbox ,其中包含一个很棒的链式安装程序,其中包括:

    • Docker Client - This is the "docker" windows command you'll use at the command line, if you want to.

      Docker客户端-如果需要,这是您将在命令行中使用“ docker” windows命令

    • Docker Machine - Docker Machine creates Docker hosts anywhere and configures Docker to talk to those machines.

      Docker Machine -Docker Machine可在任何地方创建Docker主机并配置Docker与这些计算机进行通信。

    • Docker Compose - This is a tool for defining multi-container Docker applications.

      Docker Compose-这是用于定义多容器Docker应用程序的工具。

    • Docker Kitematic - Kitematic is really accessible. It's the Docker GUI and runs on Mac and Windows.

      Docker Kitematic -Kitematic确实可以访问。 它是Docker GUI,可在Mac和Windows上运行。

      • I like to think of Docker Kitematic as "GitHub for Windows for Docker." Just as GitHub for Windows is an attractive and functional GUI for 80% of the things you'd want to do with Git, then Kitematic is the same for Docker. I personally think that while Kitematic is in alpha, it will be the thing that gets new people using Docker. It definitely made onboarding more comfortable for me.

        我喜欢将Docker Kitematic视为“适用于Docker的Windows的GitHub”。 正如适用于Windows的GitHub是您要使用Git完成的80%的功能的引人注目的功能GUI一样,Kitematic对于Docker也是如此。 我个人认为,虽然Kitematic处于Alpha状态,但它将使新人们使用Docker。 这绝对使我的入职更加舒适。

      Docker Kitematic - Kitematic is really accessible. It's the Docker GUI and runs on Mac and Windows.

      Docker Kitematic -Kitematic确实可以访问。 它是Docker GUI,可在Mac和Windows上运行。

    • VirtualBox - Oracles free and excellent Virtual Machine software. I use this instead of Hyper-V on the client. Hyper-V is great on the server or in the cloud, but it's not optimized for client software development or running Ubuntu VMs and remoting into them. Also, VirtualBox is extremely easy to automate, and Docker and Kitematic will be automating creating the VMs for you.

      VirtualBox -Oracle的免费和出色的虚拟机软件。 我在客户端上使用它而不是Hyper-V。 Hyper-V在服务器或云上都很棒,但是它并未针对客户端软件开发或运行Ubuntu VM并进行远程处理而进行优化。 另外,VirtualBox非常易于自动化,并且Docker和Kitematic将为您自动创建VM。

    Download Docker Toolbox which has a great chained installer that includes:

    下载Docker Toolbox ,其中包含一个很棒的链式安装程序,其中包括:

When you run Kitematic the first time it will automate VirtualBox and use a "boot2docker.iso" to boot up a new that will host your Docker containers.

第一次运行Kitematic时,它将自动执行VirtualBox并使用“ boot2docker.iso”启动一个新的托管您的Docker容器的容器。

VirtualBox

If you want to test things, click New in Kitematic and search for "Ghost." Kitematic will download the Dockerfile, create a VM and Container, provision everything, and run Ghost inside Docker within your (hidden from view) VM. Click Settings and you can see what port it's running on, or just click the Arrow next to Web Preview and Kitematic will launch a web browser talking to the node.js-based Ghost Blog running in Docker.

如果要测试,请在Kitematic中单击“新建”,然后搜索“ Ghost”。 Kitematic将下载Dockerfile,创建虚拟机和容器,置备所有内容,并在(从视图中隐藏)虚拟机中的Docker中运行Ghost。 单击设置,您可以看到它正在运行的端口,或者只需单击Web Preview旁边的箭头,Kitematic将启动Web浏览器,与在Docker中运行的基于node.js的Ghost Blog对话。

Note: Microsoft Edge is having some troubles talking to VirtualBox virtual network adapters, and I'm tracking workarounds here. Other browsers are fine.

注意: Microsoft Edge在与VirtualBox虚拟网络适配器通讯时遇到了一些麻烦,我在这里跟踪解决方法。 其他浏览器也可以。

Kitematic publishig Ghost

ASP.NET 5以及Linux和Docker (ASP.NET 5 and Linux and Docker)

ASP.NET 5 and the .NET Core CLR are both open source and run on Windows, Mac, and Linux. We're going to make an ASP.NET in Visual Studio and deploy it to a Linux Container via Docker. The "Dockerfile" that describes ASP.NET 5 is open source and is here on GitHub https://github.com/aspnet/aspnet-docker but you don't really need to sweat that even if it is interesting.

ASP.NET 5和.NET Core CLR都是开源的,可以在Windows,Mac和Linux上运行。 我们将在Visual Studio中制作一个ASP.NET,并将其通过Docker部署到Linux容器中。 描述ASP.NET 5“ Dockerfile”是开源的,位于GitHub https://github.com/aspnet/aspnet-docker上,但是即使它很有趣,您也不必费劲

NOTE: You can get and install ASP.NET here http://get.asp.net. Visit it from any OS and it will give you the details you need to install and get started.

注意:您可以在http://get.asp.net上获得并安装ASP.NET。 从任何操作系统访问它,它将为您提供安装和入门所需的详细信息。

An example Dockerfile for your basic ASP.NET 5 application would look like this:

基本的ASP.NET 5应用程序的Dockerfile示例如下所示:

FROM microsoft/aspnet:1.0.0-rc1-final

ADD . /app

WORKDIR /app/approot

ENTRYPOINT ["./web"]

It says, "start from this base docker file, add the files in . to ./app, and we'll be running from /app/approot. Then run ./web."

它说:“从此基本docker文件开始,将。中的文件添加到./app,我们将从/ app / approot运行。然后运行./web。”

从Visual Studio部署到Docker (Deploy to Docker from within Visual Studio)

The Visual Studio 2015 Tools for Docker are just a Preview, but they are pretty useful even in their Alpha state. Install them in Visual Studio 2015 - it just takes a second.

用于DockerVisual Studio 2015工具只是一个预览版,但是即使在其Alpha状态下,它们也非常有用。 在Visual Studio 2015中安装它们-仅需一秒钟。

Make a new ASP.NET application with File | New Project. I made one without authentication.

使用File制作一个新的ASP.NET应用程序。 新项目。 我做了一个没有身份验证的。

Go into the Project.json and change this line to include the --server.urls bit. The important part is the *, otherwise the Kestrel web server will only listen for localhost and we want it to listen everywhere:

进入Project.json并更改此行以包括--server.urls位。 重要的部分是*,否则Kestrel Web服务器将仅侦听localhost,而我们希望它在任何地方侦听:

"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000"
}

Right Click Solution Explorer and click Publish and you should see this:

右键单击“解决方案资源管理器”,然后单击“发布”,您应该看到以下内容:

Docker Tools for Visual Studio

From here, select Docker, and you will have a change to make a VM in Azure or publish to an existing VM.

从此处选择Docker,然后将进行更改以在Azure中制作VM或发布到现有VM。

Instead, click "Custom Docker Host" because we are going to public to our local VM.

相反,请单击“自定义Docker主机”,因为我们将向本地VM公开。

Here's what my settings look like. Yours will be different.

这是我的设置。 您的会有所不同。

Custom Docker Profile in Visual Studio

In order to get the settings YOU need, go to Kitematic and click Docker CLI to get a cool PowerShell preconfigured command prompt all setup with knowledge of your system.

为了获得所需的设置,请转到Kitematic并单击Docker CLI以获取一个很酷的PowerShell预配置命令,在您知道系统知识的情况下进行所有设置。

Type "docker-machine config default" and you'll get a command line showing where your certs are and the IP and port of your Docker setup.

输入“ docker-machine config default”,您将获得一个命令行,显示您的证书所在的位置以及Docker设置的IP和端口。

Note the result is missing a carriage return there after the port 2376.

请注意,结果缺少端口2376之后的回车。

docker-machine config default

Fill out the form with the Server Url, and image name, and some ports. I mapped port 5000 inside the container because I'll have the ASP.NET Kestrel web server listening on Port 5000.

使用服务器网址,图像名称和一些端口填写表格。 我将端口5000映射到了容器内,因为我将使ASP.NET Kestrel Web服务器在端口5000上进行侦听。

Here's what my "Auth Options" text box looks like. Your paths will be different.

这是我的“身份验证选项”文本框的外观。 您的道路将有所不同。

--tlsverify 
--tlscacert=C:\Users\scott\.docker\machine\machines\default\ca.pem
--tlskey=C:\Users\scott\.docker\machine\machines\default\server-key.pem
--tlscert=C:\Users\scott\.docker\machine\machines\default\server.pem

Click Validate Connection and you'll hopefully get a green checkbox.

单击验证连接,您将希望获得一个绿色复选框。

WEIRD BUG: As of this writing the November 2015 version of the preview Docker Tools for Visual Studio 2015 has a bug when publishing to a custom host. The generated .ps1 in the PublishProfile is wrong. I think they'll fix it ASAP but the fix is to fake publish a Hello World ASP.NET project to a Docker container in any Azure VM and grab the .ps1 it generates. You don't need to hit publish, the file gets generated when you hit Next. Copy that file off somewhere and copy it OVER the wrong one in your actual project. You only have to do this once. I'm sure it will get fixed soon. You can confirm you have the right .ps1 because it'll say "Docker" at the top of the file.

怪异的错误:截至撰写本文时,2015年11月版的Docker Tools for Visual Studio 2015预览版在发布到自定义主机时存在一个错误。 在PublishProfile中生成的.ps1错误。 我认为他们会尽快修复它,但修复方法是假冒将Hello World ASP.NET项目发布到任何Azure VM中的Docker容器,并抓住它生成的.ps1。 您无需单击发布,单击下一步即可生成文件。 将该文件复制到某个地方,然后复制到实际项目中的错误文件上。 您只需要执行一次。 我相信它将很快得到解决。 您可以确认您具有正确的.ps1,因为它在文件顶部显示“ Docker”。

image

When you hit publish, the project will build locally, and deploy into a new Docker container. You can watch Kitematic update as the deploy happens. The selected Container there is ASP.NET, and I know it worked because Kitematic puts a nice Web Preview there as well!

当您单击发布时,该项目将在本地构建,并部署到新的Docker容器中。 您可以在部署发生时观看Kitematic更新。 所选的容器是ASP.NET,我知道它可以工作,因为Kitematic还在其中放置了不错的Web预览!

ASP.NET 5 in Docker in Kitematic

头脑风暴的改进 (Brainstorming Improvements)

So this is what I was able to do with existing bits. What I'd like to see is:

这就是我能够使用现有位进行的操作。 我想看的是:

  • Press Ctrl-F5 in Visual Studio and have it build the project, deploy to Docker, and launch the browser all in one go. Do you agree?

    在Visual Studio中按Ctrl-F5,让它一次生成项目,部署到Docker,然后启动浏览器。 你同意吗?
    • I was thinking to make a "docker" command in the ASP.NET 5 "launchSettings.json" which would appear like this in Visual Studio.

      我当时正在考虑在ASP.NET 5“ launchSettings.json”中创建一个“ docker”命令,该命令在Visual Studio中看起来像这样。

      Docker in VS

      I was thinking to make a "docker" command in the ASP.NET 5 "launchSettings.json" which would appear like this in Visual Studio.

      我当时正在考虑在ASP.NET 5“ launchSettings.json”中创建一个“ docker”命令,该命令在Visual Studio中看起来像这样。

  • Today you have to delete the container manually in Kitematic and publish again. How would you want things to work?

    今天,您必须在Kitematic中手动删除该容器,然后再次发布。 您希望事情如何运作?
  • If Docker is promoting Kitematic as the best way to get started with Docker, should Visual Studio plugins know that Kitematic and Docker Machine are there and auto-configure things?

    如果Docker推广Kitematic是开始使用Docker的最佳方法,那么Visual Studio插件是否应该知道Kitematic和Docker Machine在那里并且可以自动配置?

Additionally, when  Windows Containers happens, Visual Studio should clearly be able to publish an ASP.NET 5 application to the container, but even better, if this Docker flow works cleanly, I should be able to publish via Docker to Linux OR Windows from the same dialog in VS. Then after a local deployment to Docker I could Right-Click Publish and publish to Docker in an Azure VM and or Azure Container Service.

此外,当发生Windows容器时,Visual Studio应该可以清楚地将ASP.NET 5应用程序发布到容器中,但是更好的是,如果此Docker流能够正常运行,我应该可以通过Docker从Docker发布到Linux或Windows。 VS中的相同对话框。 然后,在本地部署到Docker之后,我可以右键单击“发布”,然后在Azure VM和/或Azure容器服务中发布到Docker

IMHO given an ASP.NET 5 app, you should be able to:

恕我直言,如果使用ASP.NET 5应用程序,您应该能够:

  • Publish to a folder

    发布到文件夹
  • Publish to a Docker container (Linux or Windows)

    发布到Docker容器(Linux或Windows)
    • Ctrl-F5 build AND F5 debug that container.

      Ctrl-F5构建和F5调试该容器。
    • Publish to Docker in any cloud

      在任何云中发布到Docker
  • Publish to an Azure VM, Web Site (App Service), or Docker within Azure Container Service

    发布到Azure容器服务中的Azure VM,网站(应用程序服务)或Docker
  • Editor support and syntax highlighting for Dockerfiles and Docker Compose files.

    Dockerfile和Docker Compose文件的编辑器支持和语法突出显示。
  • Docker Tools for VS should make a basic Dockerfile if one doesn't exist

    如果不存在VS的Docker工具,则应创建一个基本的Dockerfile
  • Run xUnit and tests in the Docker Container

    在Docker容器中运行xUnit并进行测试

What do you think, Dear Reader? How much Visual should Visual Studio have? I personally like these lightweight dialogs that launch command line tools. How do you expect Docker to integrate with Visual Studio?

亲爱的读者,您如何看待? Visual Studio应该有多少个Visual ? 我个人喜欢启动命令行工具的这些轻量级对话框。 您如何期望Docker与Visual Studio集成?

翻译自: https://www.hanselman.com/blog/brainstorming-development-workflows-with-docker-kitematic-virtualbox-azure-aspnet-and-visual-studio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值