DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Create and Push a Docker Image From an Octopus Deployment

Create and Push a Docker Image From an Octopus Deployment

Creating an Octopus step template to create and push a Docker image to DockerHub is a good way to move from a VM to Containers while keeping the current infrastructure.

João Rosa user avatar by
João Rosa
·
Feb. 07, 17 · Tutorial
Like (2)
Save
Tweet
Share
10.67K Views

Join the DZone community and get the full member experience.

Join For Free

Docker is one of the disruptive technologies within virtualization, allowing the different containers to run on the same machine, sharing resources and 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.

Background

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 created an Octopus step template where it is possible to create and push a Docker image to DockerHub.

This fits in an organization moving from a VM environment to a Container environment, but keeping the current infrastructure (i.e., using Octopus to manage the releases, including where the packages are deployed).

The tools used for this tutorial were:

  • Visual Studio 2015 Community Edition.
  • Docker for Windows.
  • Octopus Deploy Community Edition.

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, and image name, among others.
  2. Validate the parameters, i.e., 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.

octopus-docker

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 this:

docker-octopus-project

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.

docker-octopus-step

After creating a release (potentially triggered by the CI server), Octopus Server can deploy it.

docker-octopus-deploy

If the step runs successfully, we can check the Docker image in the repository.

dockerhub-image

We can 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.

docker-container-run

Final Thoughts

The step allows the creation of Docker images from an Octopus deployment, centralizing and minimizing 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.

Docker (software) Octopus (software) push Continuous Integration/Deployment

Published at DZone with permission of João Rosa, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • When AI Strengthens Good Old Chatbots: A Brief History of Conversational AI
  • Promises, Thenables, and Lazy-Evaluation: What, Why, How
  • 5 Tips for Optimizing Your React App’s Performance
  • Required Knowledge To Pass AWS Certified Data Analytics Specialty Exam

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: