ASP.NET 5: Seamless integration with Drone and Docker

ASP.NET 5 and Docker   Microsoft provides dockerfiles to create images and docker containers containing the ASP.NET

ASP.NET 5 and Docker


Microsoft provides dockerfiles to create images and docker containers containing the ASP.NET 5 execution environment applications. The image contains the following applications:

  • dnvm: .NET runtime versions manager. Equivalent of ruby’s RVM, or virtualenv from python.
  • dnx: SDK and execution environment multi-platform of .NET applications.
  • dnu: Utility to install nuget development agencies. Equivalent to rubygems / bundler in ruby, or NPM in nodejs

Note: At this time (December 2015), dotnet is under development, a tool that combines dnx and dnu.

To serve as an example, a repository on github was created containing a simple test implemented with xunit. It can be cloned as follows:

Then we can test the application using the aforementioned image docker:

The parameters indicate the following:

  • -i: interactive mode.
  • -t: Pseudo-tty.
  • -v: Create a volume, which means, mounting the pwd within / app in the container.
  • microsoft/ aspnet: Image in which we can initiate our container
  • :1.0.0-rc1-update1-coreclr: Version of the image to use
  • /bin/ bash: command to execute within our container

Then, within the container, execute the following dependencies to install and run the xunit tests implemented:

We should have a similar output to this one:


Drone is a continuous integration platform that works on docker. Each build is performed on a new container, so if we have a docker image that provides us the tools to build and test our application, we can use drone very easily.

Webhook y github

Drone is responsible for conducting a build for each push that we’ll make to our github repository (it also supports bitbucket and gitlab). To set up drone with github, we go to “our applications” and record a new application. Github then we will give us a Client ID and Client Secret that we will use to configure drone.

Once we have the ID and Client Secret, we create a file with the following format:

Finally, we can start drone with the following command:

In -env-file we indicate the file created above, and in -publish we indicate the port that will be running on the host (80 in this case).


.drone.yml is the configuration file required to use drone on our application and should be at the root of the repository. Below, we can see the minimum .drone.yml to run the tests in our application:

Note: dnx test runs the test command as defined in project.json as dnx.runner.xunit.

In the configuration file, we define the services that we will use and configure these services. Here, build represents the service that will be configured and will handle the building and testing of the application. image indicates the docker image that we will use and commands is a list of commands to run within the container docker. All commands should return a successful exit code for the continued integration of success.

NuGet cache

Each build that drone makes will download and install all the dependencies again. To avoid this, we must cache the dependencies and retrieve them on each build. If the dependencies change, dnu restore will be responsible for resolving it.

To define a cache in drone, we use the cache service where we define files or folders to be cached. One drawback is that drone can only cache files within /drone (the working directory that defines drone inside the container), while the image of aspnet that we use installs the packages in /root/.dnx. There are ways around this, the one that we will show here is defining the DNX_PACKAGES environment variable that defines the directory where the nuget packages will be installed.

Then, we only have to define the environment variable in any folder inside /drone and cache it:

The first thing we must do is to add in the environment configuration of the build service the DNX_PACKAGES environment variable, indicating a directory in which the packages nuget will be stored inside /drone.

Finally, we configure the cache service files or folders that you wish to cache the next build.

To finish, here is the drone output when making the corresponding build on the example repository:

Share this articleShare on LinkedInTweet about this on TwitterShare on FacebookShare on Google+Email this to someone
Go Back