Create and Push a Docker Image from an Octopus Deployment

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:

Visual Studio and the Docker WebApp for the tutorial

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.

Continuous Integration Server

You can use your preferred CI server. In your CI server will need to:

  1. Publish the Docker WebApp.NET project
    dotnet publish WebAppDemo -c Release
  2. Create the NuGet package for Octopus
    Octo.exe pack --id DockerWebAppDemo --version 1.0.0
  3. 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.

Create and Push a Docker Image Octopus step template

The step template is simple and straightforward. The Powershell script:

  1. Get all the required parameters, such as the DockerHub username, password, image name, among others
  2. Validate the parameters, e. g., if they have a value
  3. Creates the Docker image
  4. Pushes the Docker image
  5. Feedback the user

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.

Octopus Project

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.


Final thoughts

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.

The step template is under the Octopus Library OSS. You can fork and add new features to it, or open an issue in my fork. All suggestions are welcome.

8 thoughts on “Create and Push a Docker Image from an Octopus Deployment

  1. Hi Joaorosa,
    i have followed your blog. it is interesting to read.
    i am looking for custom bash script for create – push docker image and pivot machine– Are you using docker installed linux machine or docker installed windows machine? i do see that you specified appLocation as C:/<> but in your docker image creation step, i do see linux permission thing. little bit confuse here.

    could you please clarify?



    1. Hi Sudheer,

      It has been a while, and back then there wasn’t a Linux version. The article was written based on the Windows Version.
      For the question that you posted, I also foresee problems with the permissions. But the script should be flexible enough to use any path, where the service account has privileges.

      Does it make sense?

      Best regards, João Rosa


      1. Yes, that make sense to me! So that you build the docker image in windows machine and trying to use this image in Linux machine , right? And if I take your docker hub image and pull it in windows , it’s saying that Linux operating system images doesn’t support on windows platform.
        How come it is possible? You are saying that you build the image in windows machine, so it should support windows machine right?
        Something I am missing here, could you please clarify details?
        And could you please share your step template script with me?



      2. okay. initially i tried to use windows container and build the image and pushed to the docker hub but when i pull to my linux environment, getting below error.
        [ec2-user@ip-172-12-0-227 ~]$ sudo docker pull sudheeramgothu/testdotnetcore
        Using default tag: latest
        latest: Pulling from sudheeramgothu/testdotnetcore
        bce2fbc256ea: Downloading
        4a14bdf6da80: Downloading
        26714a2e6283: Download complete
        3242c1a2bd2c: Waiting
        59d6fcb1cafa: Waiting
        19a189a0738d: Waiting
        d9e309541597: Waiting
        fdd4a346268a: Waiting
        973e1b33350f: Waiting
        0b705cc4da30: Waiting
        07eb24f8f2c9: Waiting
        5cff5b652ffd: Waiting
        632f3800474b: Waiting
        cd5493e8ad61: Waiting
        4ab278ff4181: Waiting
        image operating system “windows” cannot be used on this platform

        but if i pull your docker image, i am able to pull to my linux environment and able to run the application too.

        why in my environment, its failing?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s