04 February 2017
Docker is one of the disruptive technologies within virtualization, allowing the different containers to run on the same machine, sharing resources, reducing the overhead. The technology allows DevOps teams to have another tool to develop, build and ship software. One use case for containers is the Microservices Architecture Pattern.
DockerHub is the image repository offered by Docker, where we can publish public repositories (the tech community is there) or use the private repositories feature (instead of building an infrastructure in the local environment). One of the features is the Automated Builds from a GitHub or Bitbucket account. Although it is a great feature, not all software shops uses this set of technologies.
For a software shop using Octopus, there are already features to deploy Octopus images from an Octopus Deployment. However, is not possible to create and push a Docker Image based on packages stored in Octopus. To fill this gap, I create an Octopus step template where it is possible to create and push a Docker image to DockerHub.
This fits is an organisation moving from a VM environment to a Container environment, but keeping the current infrastructure, e. g., using Octopus to manage the releases (including where the packages are deployed).
The tools used for this tutorial were:
Using the Visual Studio .NET Core Web Application template for this tutorial, the project was created and committed here. The WebApp is the out-of-the-box web application.
You can use your preferred CI server. In your CI server will need to:
Publish the Docker WebApp.NET project
dotnet publish WebAppDemo -c Release
Create the NuGet package for Octopus
Octo.exe pack --id DockerWebAppDemo --version 1.0.0
Upload the AWS Lambda NuGet package to Octopus Server
NuGet.exe push DockerWebAppDemo.1.0.0.nupkg -ApiKey myApiKey -Source https://myOctopusServer
These instructions are generic, and depending on your CI server technology can be done in different ways. You can take them as generic steps, and adapt to your needs.
The step template is simple and straightforward. The Powershell script:
The step template has a prerequisite; it depends on the Docker for Windows. You need to download and install it on the machines where the step will run.
To create the Octopus image we need to use a pivot machine with Docker for Windows installed.
We will use the Octopus out-of-the-box features to deploy the DockerWebAppDemo package to the Pivot Machine, and the new step template to create and push the Docker image to DockerHub.
The Octopus Project will look like:
The first step deploys the NuGet DockerWebAppDemo package to a custom location in the Pivot Machine (with the Docker Machine role).
The second step creates and pushes the Docker image to DockerHub using the Dockerfile provided.
After creating a release (potentially triggered by the CI server), Octopus Server can deploy it.
If the step runs successfully we can check the Docker image in the repository.
Or even run it in a machine running Docker, using the following command:
docker run -p 5000:80 -e "ASPNETCORE_URLS=http://+:80" -it --rm joaoasrosa/dockerwebappdemo
If we access to a browser using the URL:port for the Docker container, we can see the application running.
The step allows the creation of Docker images from an Octopus deployment, centralising and minimising the packages maintenance operations. Also, it is possible to deploy the same package to a machine or a Docker image, increasing the deployment scenarios for a DevOps team.