次の方法で共有


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

Comments

  • Anonymous
    July 21, 2016
    I´m working with Docker beta version for windows 10 and I have an Asp Core Web application , Docker is running and I followed all the steps in the video example for a simple web application with Docker support, but in the moment which it tries to run in Docker, the console shows this error:Failed to run the command ....DockerTask.ps1 -Run -Environment Debug -Machine '' -RemoteDebugging $True -OpenSite $False". Details:ERROR: for webapplicationcore2 driver failed programming external connectivity on endpoint webapplicationcore2_webapplicationcore2_1 (6273722feb442d3621a48f2c25c6ab15d6366e2bcd8f8b5a214e717b6405fbd9): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error Unix.Unix_error(Unix.EACCES, "bind", "")Do you have any idea what is happening ?I need identify the problem, thanksRobert
    • Anonymous
      November 29, 2016
      Hey Robert,You'll probably find IIS (or another app) bound on port 80, so docker stuff won't have any luck with that. Still trying to figure out how to get docker & local apps like IIS to play nice myself.
      • Anonymous
        December 04, 2016
        Hi Robert, Gavin,As we've been iterating quickly on the Visual Studio Docker Tools, this post has become outdated when looking at the current Visual Studio 2015 or most recent Visual Studio 2017 RC tools.However, in either case, ports should be allocated dynamically, using -P which will take the port you intend to expose on your container, and find an available port on the host. You can find the port by issuing docker psSteve
  • Anonymous
    January 11, 2017
    When I added Docker Support to Project in Solution not all files are getting added.For example Docker.Props and Docker.Targets.I am using VS 2015 Pro.I am not sure why is this so.Any lead?