I've always liked to use my website to test out new technology. Recently I stopped hosting a few external sites for friends and family, which closed down my revenue stream to cover hosting charges. I was only paying $45 a month, but that adds up over a year. I needed a cheaper option to host brettmorgan.net.
Enter Docker Cloud. I've been using Docker on and off for about a year now. In my day job we successfully rolled out a UI regression testing framework using Docker. Now I could have set up Docker on my previous hosting provider, but that wouldn't saved me any money. Plus I wanted to give Docker Cloud a try.
Docker Cloud is a framework to automate the process of deploying your environment in the cloud. After a bit of research I was able to successfully migrate brettmorgan.net in one night.
Here's what I did.
Create a Node
First thing you need to do is set up a Node. A Node is the server that will have docker installed on it and will hold your containers. With Docker cloud you can have many nodes, but for my simple site I have one. The easiest way to get a node is to point Docker Cloud to a cloud provider that you already have an account with.
Since I was trying to do this on the cheap, I set up a $5/month account with Digital Ocean. I then went into Docker Cloud and filled out a simple form to create a node. This created a small server for me at Digital Ocean, it was all automated, very nice!
Create some Services
Now that I had a node, I wanted to create some services to run on it. Turns out services are just docker containers, with some extract features to link services together.
I played around with setting up a Ghost container, and an Nginx container, and basically got every thing working, all without creating my own custom Docker images. I was able to use some plain images on Docker Hub and just configure them with some environment variable and volume mappings. I did this all from the Docker Cloud UI.
This was great, but there was another feature of Docker Cloud I wanted to try out, Stacks.
Create a Stack
I wanted a change a few of my services and add my another service to my node. Rather then do this all manually through services, I decide to use the Stack feature in Docker Cloud. My understanding is that is a lot like Docker Compose (I have used so, I can't really make comparison).
The idea of a Stack is that you create a Stackfile, that specs out all your services. Then you just start your stack and all the services come up. I was really easy to set up a stack file with all the services I needed.
Here is my stack file with private stuff changed.
lb: #load balancer image: 'dockercloud/haproxy:latest' links: - ghost #linked to ghost - web #linked to web ports: - '80:80' roles: - global ghost: image: 'ptimof/ghost:latest' command: 'npm start -production' environment: - 'GHOST_URL=http://any.site.com' - 'VIRTUAL_HOST=*site.net' #lb proxies to here volumes: - '/path/to/ghost/content:/var/lib/ghost' #maps to ghost content on host web: image: 'nginx:latest' environment: - VIRTUAL_HOST=foo.site.com #lb proxies to here - VIRTUAL_HOST_WEIGHT=1 volumes: - '/host/path:/usr/share/nginx/html:ro'
Docker Cloud made deploying my site really simple.