How I Built My “Docker GOLD” Image for Rancher

In order to configure my Auto Scaling Group as I mentioned here, I needed a base AMI.  When it comes to imaging, there is a lot of debate over whether it is better to “bake” what you need into the image or to “bootstrap” when your image is launching.  I am not going to debate that here.  But I will indicate what I baked in to my AMI vs what I am bootstrapping.

Baked Into the Image

  • Started with an existing AMI for Ubuntu 14
  • Installed Docker
  • Installed AWS CLI
  • Installed the Docker Certificate for authenticating to the Docker Repository.

Script for Auto Scaling Group

Rancher Add Host
Rancher Add Host

In order to build your script you will need to know the link to the Rancher Agent install.  You can get this by going to Infrastructure in you Rancher installation and click on add host.

Select Custom

Then look in section 5 of that screen.  Copy that script.  You will add it to your Launch Configuration script.

Rancher agent install script
Rancher agent install script

 

 

Below is an example of the script I ended up with.  Items I included:

  • Change SSH port to 2222
  • Install the rancher agent. (Note that I added the e CATTLE_HOST_LABELS=RancherPool=yes section to the script.  This will add a label to the host indicating that this is a RancherPool.  I have another “pool” that is dedicated to my Graylog Server.  So that section would be different for those hosts.)
  • Mount the GlusterFS File share.  I am using this for persistent data for my containers.
  • Login to the Docker Registry.  (I am not actually 100% sure this is needed, but I assume after the instance is launched, Rancher is going to begin pushing docker containers and I wanted to be sure that they would not fail to launch.

My Script

#!/bin/bash
#Change SSH port to 2222
sudo perl -pi -e 's/^#?Port 22$/Port 2222/' /etc/ssh/sshd_config
sudo service ssh restart
#Install Rancher Agent for Rancher Pool
sudo docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher -e CATTLE_HOST_LABELS=RancherPool=yes rancher/agent:v1.0.1 http://rch.domain.com:8080/v1/scripts/D00000000000:00000000000:000000000
#Mount GlusterFS files share
sudo mount -t glusterfs glusterfs1.panosoft.com:vol1 /app
#login to my Docker Registry
docker login -u docker -p "dd0cker1" -e docker@domain.com reg.domain.com:5000
Boot script for Launch Configuration

NOTE: Replace line 6 with your agent install script.  Remember to add the Host Label section.

Follow by Email
Facebook
Google+
http://cloudlady911.com/index.php/2016/08/06/how-i-built-my-docker-gold-image/
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *