Continuous Integration using TeamCity & Docker for ASP.NET Core

Note: Please read the previous posts before continuing with this one, I discuss the basics of Docker and show how to deploy a simple and multiple applications using Docker. In this post I will use the code from first post and demonstrate continuous integration with TeamCity.


How to use Docker and TeamCity to implement continuous integration for ASP.NET Core applications.


First we need to setup TeamCity. Since I like Docker, I’ll setup TeamCity within Docker too, using the below docker-compose.yml, just run docker-compose up from the path where this compose file is located:

This will pull images and start TeamCity on localhost:8111, go through the simple steps to configure TeamCity.

Once TeamCity is running, configure an Agent. Click the “Agents” link (top menu), go to Unauthorized, click on the agent from a list and click Authorize Agent button:

Next create a new project by clicking Projects link (top menu):

Choose “From a repository URL” and paste the link to your repository:

Type name for your build configuration, I’ve left as default:

Next you’ll be asked to configure build steps, click the link “configure build steps manually”:

Next choose “Command Line” as Runner Type and add custom script that uses Docker to build images:

Note: this assumes that the Dockerfile is in the root of solution folder. See the source code on GitHub for reference.

Save and click Run button on top-right to test the build step:

Once the build is complete, you could view the logs:

Run docker images command to view the image created by TeamCity:

Run a container based on this image:

Browse to http://localhost:8080/api/movies to test the application.

Now make changes to your application and commit. TeamCity will kick off a new build:

And once the build is complete, you’ll have another image:

You now have multiple versions of your applications to test, run and deploy. Below I ran the two versions on two different ports:

When I was playing with this, I accidentally broke tests for my application and TeamCity didn’t build (as a result no image was created):

With very little effort we are able to package multiple versions of our application, thanks to Docker.

Note: For more complex scenarios you could use a docker-compose.yml to run your applications rather than docker run command.

Source Code



    1. Currently I don’t have an example, I recommend downloading the code and trying it out. Basically you’ll need to change the context in dockerfile from . to something like ./myfolder/myfolder/ so that the dockerfile uses that path to get files for the image. Let me know how you get on.

Leave a Reply