Here, we'll deploy a Ghost blog with an NGINX reverse proxy, all on Docker, using an Ubuntu Xenial 16.04 on AWS EC2! This is to simulate a real deployment of an application, so you can see if it is working in real conditions.
Begin by installing the plugin:
A requirement of this plugin is the presence of a dummy Vagrant box that does nothing:
Remember how we configured the Docker provider in the previous recipes? This is no different:
Then, defining an application VM will consist of specifying which provider it's using (AWS in our case), the Amazon Machine Image (AMI) (Ubuntu 16.04 LTS in our case), and a provisioning script that we creatively named script.sh
.
You can find other AMI IDs at http://cloud-images.ubuntu.com/locator/ec2/:
So what is the AWS-related information we need to fill in so Vagrant can launch servers on AWS?
We need the AWS Access Keys, preferably from environment variables so you don't hardcode them in your Vagrantfile:
Indicate the region and availability zone where you want the instance to start:
Include the instance type; here, we've chosen the one included in the AWS free tier plan so it won't cost you a dime with a new account:
Indicate in which security group this instance will live (it's up to you to adapt the requirements to your needs):
Specify the AWS keypair name, and override the default SSH username and keys:
Under some circumstances, you can experience a bug with NFS while using Vagrant and AWS EC2, so I choose to disable this feature:
Finally, it's a good practice to tag the instances, so you can later find out where they come from:
Add a simple shell script that will install Docker and docker-compose
, then execute the docker-compose file:
Include both NGINX configuration and docker-compose.yml
files from the previous recipe and you're good to go:
Open your browser at http://a.b.c.d/
(using the EC2 instance public IP) and you'll see your Ghost blog behind an NGINX reverse proxy, using Docker containers, using Vagrant on Amazon EC2.
A common usage for such a setup is for the developer to test the application in close to real production conditions, maybe to show a new feature to a remote product owner, replicate a bug seen only in this setup, or at some point in the CI. Once Docker containers have been built, smoke test them on EC2 before going any further.