Octopus Deploy is a Continuous Delivery tool (much like Azure DevOps and Jenkins) that allow us to deploy our artifacts and code to infrastructure. This allows us to not only automate our deployments, but to ship quickly to our customers and end-users. Today we're going to learn how to deploy an Octopus Deploy instance to Docker.

Prerequisites;

1. A machine running Docker

2. The ability to use Windows container

Before you begin, please ensure you switch to Windows containers if you are running Docker on your desktop.

The first thing we'll need to do is configure our .env configuration. This holds our variables that will be passed into our Docker Compose file. Simply name it ".env" and put it in the same directory as your Docker Compose file. Below is what mine looks like:

SA_PASSWORD=P@ssw0rd!
OCTOPUS_VERSION=2018.3.13
OCTOPUS_ADMIN_USERNAME=admin
OCTOPUS_ADMIN_PASSWORD=SecreTP@assw0rd

Once that's saved, I'll start configuring my Docker Compose file. We will need two docker images for this. SQL Express and Octopus. You can absolutely use a SQL server for this if you're running in production. In fact, I highly recommend not running a SQL container unless you have a connection string pointing from your SQL container to an actual database. For example, you can run a MySQL container, but point the containers connection string to an RDS instance (Database Service in Azure). The reason for this is containers are supposed to be ephemeral and are not persistent. For the purposes of this demo, I'm running it in a Dev environment, so a SQL express container is just fine.

version: '2.1'
services:
 db:
   image: microsoft/mssql-server-windows-express
   environment:
     sa_password: "${SA_PASSWORD}"
     ACCEPT_EULA: "Y"
   healthcheck:
     test: [ "CMD", "sqlcmd", "-U", "sa", "-P", "${SA_PASSWORD}", "-Q", "select 1" ]
     interval: 10s
     retries: 10

Above is where to configure the version of Docker Compose that is being used and where to start services. The first service is for a database. Pull the SQL Express image and utilize variables that are created in the .env configuration for the DB password.

octopus:
   image: octopusdeploy/octopusdeploy:latest
   environment:
     OctopusAdminUsername: "${OCTOPUS_ADMIN_USERNAME}"
     OctopusAdminPassword: "${OCTOPUS_ADMIN_PASSWORD}"
     sqlDbConnectionString: "Server=db,1433;Initial Catalog=Octopus;Persist Security Info=False;User ID=sa;Password=${SA_PASSWORD};MultipleActiveResultSets=False;Connection Timeout=30;"
   ports:
    - "8081:81"
   depends_on:
     db:
       condition: service_healthy
   stdin_open: true

Above is for Octopus. Here is where you specify the Octopus image, set up your connection to MySQL, what ports you want the UI to listen in, dependencies which in the DB, and service conditionals.

The end state of the Docker Compose file should look like the below screenshot.

You are now ready to run our Octopus deployment. CD (change directory) into the directory where your Docker Compose and .env configurations are.

Now run docker-compose up to initiate the deployment. This could take a little while. Both of the Docker images we're using are pretty large (2-4GB each).

Octopus will now start deploying.

Once you see "Listening for HTTP requests on", you're ready to connect to the UI. Open up a web browser and type in localhost:8081.

You can now successfully log in with your username and password specified in the .env configuration.

You are now ready to start configuring Octopus Deploy.