Play Detective w/CloudFormation

Goal:

Configuration draft is like poetry, & everyone hates poetry…Cloudformation can assist in bringing the stack back in sync to the original template after IDing the drift.

Lessons Learned:

  • Create CloudFormation Stack
  • Terminate an EC2 instance for stack drfit
  • Eliminate drift from stack

Create Key Pair:

  • Before you get into the house, gotta have keys right?!

Create CloudFormation Stack:

  • I think what AWS has in the “infrastructure composer” is sick, both options of “canvas” and “template” are so slick, also toggling between “YAML” & “JSON” is epic!
  • After the template is created, go ahead & select your VPC as well as subnet of choice
  • Tahhhhh DAhhhhhhhhhhhhhhhhhh!!!!

Terminate an EC2 instance for stack drift:

  • Annnnnd now its time to run some EVILLL experiments, muuhh-hahahaha… ahemm..
    • Go to your EC2 instances
  • Change instance 3 security groups
  • Delete/Terminate instance 1!!
  • Now edit your security group inbound rules
    • Add HTTP & HTTPs
  • Go to S3
  • Detect drift on CloudFormation stack
  • You can see the details of your drift detection & compare the before/after

Terminate Drift on Individual Resource:

  • Put the “afterdriftdetection” file in & prepare for re-upload

Update Stack to Eliminate Drift:

  • Go giggles, you can manually re-add the security group and re-enable the s3 static web hosting… OR just upload the other file & see the magic happen.
    • Cuz as as seen above, AWS tells you the difference for the drift & w/that code you can re-update the file for re-upload. #ohhhyeaaaaah
  • Dont forget to delete your stack if your done, orrrr it will stay there – – – … 4Evahhhh

Gettin’ cheaper infrastructure w/CloudFormation

Goal:

GREAT-SCOTT! One just realized our EC2 instance is more compute power than required, & thats not all! Plus were spending wayyy to much chedahhhhhhhh (we want to save for more other goodies – like Pokemon cards & new fancy coffee mugs.. just a thought)

Lessons Learned:

  • Configure InstanceType Parameter to “t3.micro”
  • Launch Updated stack & ensure EC2 can connect

The Appetizer before configuring “t3.micro” & Updating the stack:

Configure InstanceType Parameter to “t3.micro”:

  • After maneuvering to your CloudFormation stack & selecting update – take a peak at the template as seen below.
    • Don’t fret, all these lines can be leveraged from the link above in the github repository.
  • Screenshot below shows the “Default: t3.small” that requires update
  • This is a perty-neat feature I thunk you would find dope. Instead of lines of code, you can mold your own visual CloudFormation by selections on the side.
    • OR you can just see how each AWS service connects to one another.
  • After you make the minor edit for the EC2 size, select validate
  • Once that is complete, your screen will look like this below

Launch Updated stack & ensure EC2 can connect:

  • Queue Jeopardy theme song…
    • After a couple minutes you will see updates to your template
  • Scroll down to find your instance ID to see if your instance update is complete
  • SEEE!??!
  • Wanna double check? Go to outputs & lastly snag your Public IP address

The Watcher, of all Containers

Goal:

  • Learn to use Watchtower to update all images running in containers simultaneously

Lessons Learned:

  • Create Dockerfile
  • Build Dockerfile
  • Push image to Docker Hub
  • Create Watchtower container
  • Update Docker image

SSH & Create the DockerFile:

  • After SSH, the DockerFile was created w/around 6 instructions

Build the Dockerfile:

  • docker image build -t earpjennings3/lab-watchtower -f Dockerfile .

Create Container:

Create Watchtower Container:

Update Image:

Re-Build the image:

Re-Push Image:

View to see image updating as instructed:

Portainer? Never heard of her!

Goal:

  • I have a lot of servers to manage & the Docker servers are getting plentiful, so lets see if Portainers can help

Lessons Learned:

  • Create a volume
  • Create a portainer
  • Login to Portainer

Create Volume & Portainer:

  • Few steps to make life easier in this “master-piece”
    • SSH
      • Connect to public IP address
    • Create portainer w/command –
      • docker volume create portainer_data
    • Run portainer w/command –
      • docker container run -d –name portainer -p 8080:9000 \
        • – d = run in background
        • Make sure portainer is mapped port 8080 to 9000
        • Ensure a restart policy is set to always w/a bind mount that maps var/run/docker.sock to container
    • List container w/command –
      • docker container ls

Login to Portainer & Create Container:

  • Login to Portainer
    • Create user
  • Go to local
  • Create container:
    • On port 8081
    • From nging:latest image
  • Go to URL

<Docker> – Hub goin up on a Tuesday!

Goal:

  • So you got a Dockerfile now huh? Well lets celly & go the Hub!

Lessons Learned:

  • From CLI:
    • Login to DockerHub
    • Git Commit Hash
    • Build image
    • Tag image
    • Push image to Dockerhub

SSH, Login to DockerHub, & Git Commit Hash:

  • W/the command:
    • git log -1 –pretty=%H
  • This provides the Git commit hash as the image tag

Build Image:

  • W/the command:
    • docker image build -t (see below for details)

Tag Image:

  • W/the command:
    • docker image tag (see below for details)
  • W/the command:
    • docker image push (see below for details)

Push image to Docker Hub:

Wanna Dock<er> some Secrets?

Goal:

  • Secure crucial data/info on MySQL DB & deploy the container as a SWARRRRM w/…secrrrrrretzz!

Lessons Learned:

  • Create secrets!
  • Create MySQL Service

Initiate Connection from Manager to Worker:

  • Connect w/command:
    • SSH into public IP address
  • Begin to conduct swarm w/command:
    • Perform docker swarm init \

Create Secrets:

  • Generate passwords for MySQL root & MySQL secrets to be created

Create Network:

  • Create network for docker secret passwords to be safe in!

Create MySQL Service:

Frakenstein a WordPress Stack from Docker Compose

Goal:

  • Only fitting to create WordPress site w/MySQL using (Queue dramatic music for effects)…
    • SWARRRRRM! from a compose file to deploy a stack

Lessons Learned:

  • Setup a swarrrrrrm!
  • Compose the file w/the pertinent SQL, volume, network, & WordPress information
  • Stack deploy the wordpress blog
  • Set up WordPress!

Swarm setup:

  • SSH again into node manager & create the swarm join connection token for the worker
  • Once the docker swarm join –token command is created, copy-pasta into your worker node
  • To view your nodes, run the command below
    • docker node ls

Compose file:

WordPress blog:

  • To put your Docker compose stack to the test, run the following command:
    • docker stack deploy –compose-file docker-compose.yml wp
  • To view your service/stack, run the commands below
    • docker stack ls
    • docker service ls

WordPress setup:

  • Taaaaah-daaaaahhhhh!!

Docked some Containers

Goal:

  • Create Container from Docker Hub for environment

Lessons Learned:

  • Create Container using Nginx Docker Hub
  • Used Docker commands to set Nginx server to access on port 80
  • Build image & test

Create Container:

  • — = renamed container
  • -dt = run in background
  • ls & cat = ensure we have the correct file

Mkdir & cp:

Nginx to port 80:

  • chown =
  • – R =
  • – s =

Connect/inspect to port 80:

  • – curl = double check to IP-Address

Commit & Run image:

Stacks on Stacks of Docker Swarmzzz

Goal:

  • Migrate my plethora of Docker Containers w/Docker SWARRRRRRM

Lessons Learned:

  • Set up Swarm cluster w/manager & worker nodes
  • Test cluster

Initialize the SWARRRM:

  • Connect w/command:
    • SSH into public IP address
  • Begin to conduct swarm w/command:
    • Perform docker swarm init \
  • Establish private IP address w/command:
    • –advertise-addr
  • BOOOOM, now your an assistant-to-the-regional-manager!
  • Now you receive a command to place in your worker node, you did create a worker node…right?
  • Once your worker node is connected, quick see your list of nodes w/command:
    • docker node ls
  • Now create Ngninx service for the swarm w/the command above
    • (see above for the 4 lines of code)
  • To quick see your list of services w/the command:
    • docker service ls

Add Worker to Cluster:

  • Connect w/command:
    • SSH into public IP address
  • Add worker node to manager node w/command seen below
    • (see below for lengthy command)

Build Docker Image w/Dockerfile

Goal:

  • Figured I should start from the basics to see how one can create an application from an file. Then in turn any updates/changes can be generated in an image w/out having to update the file at all. #swish

Lessons Learned:

  • Create Dockerfile
  • Test/Build the image using the file
  • Launch the container from port 80

Create DockerFile:

  • After you SSH, now you can do the things below…

Build the Image:

Test the image from port 80