Offline Microsoft Silverlight Applications



Defaulting to Docker for Windows with Docker Tools for Visual Studio


When using Docker Tools for Visual Studio, we default the Docker host to use Docker Toolbox. Or, more specifically, we set the default docker machine to be named default, which people typically create a VirtualBox host named default. This is documented here.

Docker for Windows doesn't use Docker-Machine, rather assumes no HOST entries are set. To make Docker Tools for Visual Studio work with Docker for Windows, we'll need to change the host. In the Debugging apps in a local Docker container walk through, we show how to change the host once added to your project. However, if you're always using Docker for Windows, why not change the default template?

Our intention is to move to Docker for Windows as the default host once it's released publicly, and make this docker.props an easier file/designer to edit. In the meantime, if you're using Docker for Windows, and want to set the default to use it as your host, you can edit the Visual Studio template with the following steps.

    • Launch Notepad as Administrator
    • Open C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplatesCache\CSharp\Docker\1033\Docker.ASPNetTemplate.zip\Properties\Docker.props
    • Remove  $DockerMachineName$  from the following line
      <DockerMachineName Condition=" '$(DockerMachineName)'=='' ">$DockerMachineName$</DockerMachineName>
      it should now look like:
      <DockerMachineName Condition=" '$(DockerMachineName)'=='' "></DockerMachineName>
    • Save the file

You're all set. The next time you Add Docker Support to your project, it will now default to the Docker for Windows beta.


Deploying Docker Images from the Azure Container Registry to Azure Container Instances


In just a few minutes you can easily deploy Docker Container Images using just a context menu from the repositories blade of the Azure Container Registry.

Azure Container Instances allow you to deploy Container Images directly without first provisioning VMs, Container Orchestrators, or any other container infrastructure. With Azure Container Instances, you pay just for what you use. Azure Container Instances are not a replacement for Container Orchestrators, in fact you may run your Container Orchestrator hosts on Container Instances to give burstable resources. For more about Azure Container Instances, see this post from Corey: Fast and Easy Containers: Azure Container Instances

Seeing is believing, so here's a video on just how easy it is.

Enjoy,

Steve


Deploying to Linux & Windows Docker Containers


Last week we shipped an update to the Docker Tools for Visual Studio adding support for Windows Containers.

While the tools support both Linux and Windows, and you can deploy the same project to Linux and Windows, we didn't necessarily optimize for this scenario because:

  • We wanted to stay true to the Docker standard, which uses a single Dockerfile
  • We didn't think developers would deploy to both, and it was only us "demo jockeys"  (PMs) that wanted to deploy to both

As it turns out, people kicking the tires like the idea of deploying to Linux and then deploying to Windows to see how it works. Or, your also riding the demo horse. 

The source of the problem - horse, not the cart, and not sure if it's the chicken or the egg - that's a much larger problem that only a special pig was able to solve:

Linux and Windows have different content to build the image:

In the Docs: https://azure.microsoft.com/en-us/documentation/articles/vs-azure-tools-docker-hosting-web-apps-in-docker/, we do call this out, but we know that if the tools do a great job, you shouldn't have to read docs... :)

Note that the Docker file is specific to the operating system. If you choose to republish to a different OS, you'll need to rename the Docker file so that Visual Studio can create a new default based on the target OS. For instance, if you first publish to a Linux container and later decide to publish to Windows, you should rename the Docker file to a unique name, such as DockerLinux. Then, when you republish to Windows, Visual studio will recreate the default Docker file for Windows. Later, when you republish either one, just select the appropriate Docker file for the OS.

What is a Dockerfile?

A Dockerfile is the definition for how to build the Container. Remember, in Docker, you're not just deploying an app to a target environment. You're building a component of the environment, which includes the app. The Dockerfile defines the baseline OS Image, where to get the app, and how to start the app. Among many other options. 

If you're building for Windows and/or Linux, by definition you're targeting different environments, or for Docker, your targeting different container types. Linux or Windows, and of course which version of Linux or WIndows.

Lets take a look at the content of the DockerFile

Linux Dockerfile

If you first published to Linux, your Dockerfile would contain the following:

FROM microsoft/aspnet:1.0.0-beta6
ADD . /app
WORKDIR /app
ENTRYPOINT ["./kestrel"]

Windows Dockerfile

Docker Doc References

If you first published to Windows, your Dockerfile would contain the following:

FROM windowsservercore
ADD . /app
WORKDIR /app
ENTRYPOINT ["cmd.exe", "/k", "web.cmd"]

Dockerfile format

The details of the Dockerfile are this:

FROM - what is the baseline OS image you want to use?

ADD - add the output of your compiled app

WORKDIR - set the working directory for the entry point

ENTRYPOINT - what should be started when the container spins up? Remember, this isn't just a normal Windows Server with IIS. It's a dedicated container for specific scenarios. 

How do I deploy to both Linux and Windows?

When you initially run the publishing experience in Visual Studio, the Docker File textbox is blank, with a watermark of (auto generate) as we're happy to create the default Docker File for you, based on the target OS:

 

Once you hit publish, the app and container are built and run. If you re-enter the publish dialog will now contain the default Docker file:

Renaming the Docker File

Once the publish is finished, and the default Docker file is created, simply rename the Docker file within solution explorer

Name it DockerWindows or DockerLinux, or whatever you'd like. Put it in a sub folder for Windows\Docker or Linux\Docker. The point is isolate the two docker files related to the target OS

Go back to the publish wizard. This time, use the [...] and select the renamed docker file.

Summary of Steps

  1. Provision a Linux Container Host
  2. Publish to the Linux Host
    Docker Tools for Visual Studio will create a default DockerFile for Linux
  3. Within Solution Explorer, rename the DockerFile to DockerFileLinux
  4. Publish again, this time selecting the renamed DockerFileLinux 
  5. Provision a Windows Container Host
  6. Publish to the Windows Host
    Docker Tools for Visual Studio will re-create the DockerFile as it doesn't see the previous file as it was renamed
  7. Within Solution Explorer, rename the DockerFile to DockerFileWindows
  8. Publish again, this time selecting the renamed DOckerFileWindow

Your project should now look something like this:

  1. Your Linux and Windows Dockerfiles
  2. Azure Resource Manager (ARM) Templates and parameter files for creating the Docker Container Hosts
  3. PowerShell scripts to run the ARM templates

 

I hope that helps explain our tooling options, and perhaps peeks into the details a docker a bit with the contents of the DockerFile

Thanks,

Steve


Developing ASP.NET Apps in Docker Containers


This week we released our latest Docker Tools for Visual Studio which continues our journey for developing apps in their target environment with Docker containers.

Our 3 step goals have been the following:

  1. Run code in a container
    Switch the Visual Studio F5 experience from running code on your development machine to running in a the target operating system/environment using Docker Containers
  2. Edit & Refresh
    Make changes to your code, without having to rebuild the container each time
  3. Break-point debugging
    Set a break-point, hit F5, ...just as you have today

With release 0.10, we have reached milestone 2 and we wanted to get your feedback.  For more info on our Docker Tools journey, you can read this post.

Channel 9 Video

An interview on Channel 9 with Seth Juarez

The developer workflow:

  1. Take an existing ASP.NET 5 RC1 based web application
  2. Enable Docker Support using the Project context menu for Add --> Docker Support
    This will add docker assets you'll need for containerization and some visual studio files.
  3. Hit F5 to start running your application in the target operating system, with Docker Containers
    The PowerShell DockerTask.ps1 script runs building and running your containers using Docker-Compose
  4. You make changes to your files within Visual Studio.
    As you save the files, ASP.NET will rebuild your code and you can refresh the browser to see your changes
  5. Once you're happy with your debugged app, you'll rebuild the docker image in release mode and re-validate
  6. If you're happy with everything, you can either check in your code to your favorite SCC solution, or skip to pushing your release based image to your docker repository.
  7. If your using a SCC and CI/CD solution, you'll rebuild the container images using a dockerfile.integration and docker-compose.integration.yml file with the DockerTask.ps1 PowerShell script to build and instance your integration containers in your CI system
  8. Assuming your integration tests pass, you'll use docker push to push the validated image to your docker repository
  9. The CD solution will use a Docker-Compose.Staging.yml file to instance the containers using the image pushed to your repository

A walk through

Rather than repeat the steps, Tom covers  the pre-reqs and basic experience in this article.

Looking deeper into the docker assets added to your project:

An important design goal for our Docker tools was enable your development work, not impose glass ceilings, putting the code in your project you would have added yourselves. We don't abstract or change the way the underlying runtimes or tooling work. The Docker Tools for Visual Studio scaffold the assets, getting your started with the "smart" or common defaults. As you want to enhance or change the sequence, you simply edit the files in your project. Success for us means you find these tools handy even after you've become an expert with Docker.

Let's look at the files in more depth:

  • \Docker\Dockerfile.debug Dockerfiles are used to build a docker image. It includes the base OS [FROM ], copies the code that executes in the container, runs some commands and sets the ENTRYPOINT when the container is instanced
  • \Docker\Dockerfile.release
    The release version of the dockerfile that removes the developer optimizations, such as volume mapping and the DNX Watch functionality. The release build is what you'd use to push to your docker repository once your validation tests complete successfully
  • \Docker\Docker-compose.debug.yml
    Docker-Compose.yml is a definition file used to instance one or more containers with the docker-compose command. Docker-Compose may instance containers you've just built with a dockerfile, or may instance existing containers using the image reference. In this case, we reference the dockerfile as we're building a debug version of the container to enable the Edit & Refresh scenarios and provide developer optimizations. The basic premise of docker-compose.yml files are configuration information for instancing containers. dockerfiles contain the image definition, and docker-compose.yml files instance configuration.
  • \Docker\Docker-compose.release.yml
    This is the definition for your release configured containers. If you compare the debug and release versions, you'll see some subtle differences. The most obvious is the remove of the Edit & Refresh scenario that uses DNX Watch and Volume Mapping.
  • \Docker\DockerTask.ps1
    A PowerShell script for building the docker images and instancing them with Docker-Compose Up. The script was added so developers had more control over how the tasks were completed. Docker is a quickly evolving technology and we found developers needed more functionality and options than we could develop in some configuration UI. Instead, the docker tools provides a scaffolded script for the common needs, and allows you to extend or alter the specific steps and/or parameters.
  • .dockerignore .dockerignore is a file used by docker build, or docker-compose build that tells the docker runtime to ignore certain files from being copied to the container. This is an important optimization step to avoid docker from re-creating cached image layers. These are files you wouldn't need in your containers, and therefore hide them from the docker image which avoids invalidating the image cache when they change.
  • Docker.targets &  Docker.props
    These are files used by Visual Studio to hook the F5 experience. We don't believe you'll need to edit these files and are hoping to incorporate them into the existing Visual Studio project files. If you do find scenarios you need to edit them, we'd like to hear about them
  • launchSettings.json
    This file already existed in your project. However, the  Docker entry point was added to enable running in a Docker Container. In the 0.10.* release, you may need to edit this file to keep the DockerTask.ps1 PowerShell script from closing upon an error. See my other post for more details and troubleshooting.

Next Steps

If your working with ASP.NET and looking for how to use Docker, give our tools a whirl and let us know what you think.

In a future post, I'll discuss how to use docker-compose, environment variables, secrets, images and docker-compose.integration.yml files for instancing your containers from your docker registry. As a preview, you can view this repo with a prototype and a ppt that shows the developer workflow

More docker tools from Microsoft

We have a few other efforts we've been working on to get a full breadth of experience and engage with developers already using Docker in production:

Seeking your feedback

We're excited to get these early releases to you helping developers make the transition to a containerized application workflow. We're working hard to give you the best Docker container experience and we'd like your feedback. You can provide feedback in the MSDN Forum with docker in the title, or provide us some feedback here.

Thanks and we're looking forward to your feedback,

Steve


Docker Containers as the new Binaries of deployment


In prep for .NET Conf, I was asked by Vaso to explain some of the benefits of containers. I was talking with one of our engineering leaders in Azure, John Gossman about how we view containers more broadly. Our Azure Container Service is our Microsoft Container Orchestration solution, offering Container as a Service (CaaS).

We'll be adding container support to Service Fabric, which we think of as a Micro service PaaS.

When people think of containers, are they a specific app pattern, or the new app deployment model, for all app solutions?

To answer the benefits of Containers compared to VMs, here's an overly simply answer:

  • Containers spin up in seconds, compared to several minutes of a VM
  • Containers provide much more density, allowing you to run many more containers on a single VM, compared to how many VMs you could run on a host OS. This is achieved through a shared kernel model
  • Containers are designed to be instanced multiple times, from a single Image - in the same seconds metric
  • Docker hosts have a caching model for images, allowing them to spin up quickly
  • Containers are deployed using a Docker Registry,which handles a layering system, allowing only the deltas to be deployed across the network

With these primitives, a host of new scenarios are available, such as:

  • Instancing containers on demand for tasks, rather then leaving them running all the time.
  • Auto scaling, self healing, in seconds.
  • Blue/Green deployments, that don't require you to keep the old instances running.

Today, we think of deploying code as binaries. We compile the code, we deploy those binaries to environments we prep to accept those specific binaries, and update the environment for each app/service version change we make.

If we look forward, we see containers as the new binary. You build/compile your app as a container (Docker) image. You then deploy your app/image to generic environments. Today, these are Container Orchestration systems, like ACS with Mesos and Swarm. Kubernetes, etc. If you look forward, when doing PaaS solutions, like WebSites, App Services, any cloud deployed solution, why would you deploy individual binaries? Wouldn't it be nice if containers were the new binaries of deployment?


Docker For Windows Beta Released


Today, docker announced and released a replacement for Docker Toolbox.

There are many enhancements, including my top ...6

  1. Works with Hyper-V
    Docker Toolbox utilized VirtualBox. An alternate Virtualization technology that meant developers had to disable Hyper-V. Which means they can't run VMs or the various developer emulators, which also use Hyper-V
  2. Starts automatically - no more docker-machine start default
    The docker process will start automatically, by default.
    D4WSettings
  3. Resolves much of the problems VirutalBox had with Volume Mapping
    VirtualBox used the c:\users directory, Which meant if you placed your project under c:\Source\Github, you couldn't access your code from within the container. There in theory was a way to fix that, but we never did get it working. Now, it's just a checkbox, provide your credentials for the host to mount the share, and voila. It's just that easy.
    D4WVolumeMappingPowershellD4WVolumeMappingHost
  4. Terminal Window directly to the host
    There are times when you just want to jump on the host VM and see what's going on. Including troubleshooting your own container configurations, or the sometimes connectivity issues between your client and the host. Just right-click Moby in the system tray and choose the Developer Console
    You'll need to login first, so just enter root and hit enter. You can then run your standard docker commands
    D4WContextMenuD4WConsole
  5. Update Notifications
    In the spirit of ease of use, Docker has integrated auto update notifications, or the ability to disable it, and check for updates
  6. No need for docker-machine, sort of...
    This is slight bit of a change, and you may be switching between various hosts, including those in Azure or other hosts on your local network.
    You may be used to using docker-machine env [hostname] | Invoke-Expression
    Since Docker for Windows doesn't depend on docker-machine, you actually need to clear the environment variables. Which is the default case.
    If you're switching between an AzureHost and your Docker for Windows Host, use: docker-machine env -u | Invoke-Expression to clear environment variables.
    If you haven't used docker-machine, then you're good to go, and don't need to use docker-machine.

Docker Tools for Visual Studio Update

We have been working with docker on their latest tools and will release an update to support the local docker host shortly.

Give docker a shout, and give it a whirl. Developing apps in containers is far easier than just treating docker as a deployment technology...

Steve


Docker for Windows, Creators Update and Volume Sharing Linux Containers


If you're attempting to use Volume Sharing with Docker for Windows after you've installed the Creators Update, you may get errors indicating a Firewall Port must be opened.  This combination of the Creators Update, Domain Joined machines and enabling volume sharing has had a recent regression we're working to resolve.

Note: this only applies to Linux Volume Sharing. Be sure Docker for Windows is set to Linux.

dockerforwindowscontextmenu

Steps to re-enable volume mounting:

  1. Open Explorer, right-click on drive C and select properties
  2. Click the Sharing tab and then Advanced Sharing button
  3. Check the Share this folder, hit [OK], and then close
    advancedsharing
  4. Repeat above steps for other drives that you want shared  (I did this for C,D, and E), all my local drives in case it matters
  5. Open Control Panel\Network and Internet\Network and Sharing Center
  6. Select the vEthernet (DockerNAT) connection
    vethernetdockernat
  7. Click [Properties]
  8. Select File and Printer Sharing for Microsoft Networks
  9. Choose Uninstall, and [Yes] to the dialog that appears
    removefileprintsharing
  10.  Click [Install..]  and select "Service"
    addnetworkservice
  11. Click Add.. and then select "File and Printer Sharing for Microsoft Networks"
  12. Close all the dialogs
  13. Open Docker for Windows and share the drives again

This should get you going. If not, please help us understand what's unique.

We hope to post an update here that all you need is to simply update ___ and you'll no longer need this workaround.