Docker, Nginx and WordPress

https://medium.com/aws-activate-startup-blog/running-services-using-docker-and-amazon-ec2-container-service-bde16b099cb9#.6fnm215tc

 

object In AWS ECS
docker
  1. A server which is a type of long-running program called a daemon process.
  2. A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
  3. A command line interface (CLI) client.The Docker client can either be installed local to the daemon, or on a different host altogether.
dockerfile A Dockerfile is a text file that describes how to “build” the image. tasks?
libcontainer Execution environment of container; interface to various Linux kernel isolation features, like namespaces and cgroups
Linux cgroup (abbreviated from control groups) is a Linux kernel feature that limits, accounts for and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.
Linux namespaces are a feature of the Linux kernel that isolates and virtualizes system resources of a collection of processes. Examples of resources that can be virtualized include process IDs, hostnames, user IDs, network access, interprocess communication, and filesystems. Namespaces are a fundamental aspect of containers on Linux.
Image build component of a container. It is a read-only template from which one or more container instances can be launched. Conceptually, it’s similar to an AMI.
Registry used to store images. Registries can be local or remote. When we launch a container, Docker first searches the local registry for the image. If it’s not found locally, then it searches a public remote registry, called DockerHub. If the image is there, Docker downloads it to the local registry and uses it to launch the container.
Container is a running instance of an image. Docker uses containers to execute and run the software contained in the image.

 

Setup CLI – http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-msi-on-windows

  1. Install python
  2. Install pip
  3. yum install aws-cli
  4. aws configure (setup access key ID, access key and default region)
  5. aws ec2 describe-instances
  6. aws ecs  list-container-instances
  7. aws ecs describe-container-instances –cluster wordpress –container-instances e22a5fc8-3655-4941-aabd-c91b591e39dc

 

https://medium.com/aws-activate-startup-blog/running-services-using-docker-and-amazon-ec2-container-service-bde16b099cb9#.yzqpaowtw

  1. Create ECS cluster using GUI or CLI
  2. aws ecs create-cluster –cluster-name “wordpress”
  3. Create task definition Tell ECS how to run containers that comprise wordpress application – create task definition
  4. Create service

 

{
 “containerDefinitions”: [
   {
     “name”: “wordpress”,
     “links”: [
       “mysql”
     ],
     “image”: “wordpress”,
     “essential”: true,
     “portMappings”: [
       {
         “containerPort”: 80,
         “hostPort”: 80
       }
     ],
     “memory”: 400,
     “cpu”: 10
   },
   {
     “environment”: [
       {
         “name”: “MYSQL_ROOT_PASSWORD”,
         “value”: “password”
       }
     ],
     “name”: “mysql”,
     “image”: “mysql”,
     “cpu”: 10,
     “memory”: 400,
     “essential”: true
   }
 ],
 “family”: “wordpressFamily”
}

 

Sample YML

 

version: ‘2
services:
 wordpress:
   image: wordpress
   cpu_shares: 100
   mem_limit: 404288000
   ports:
     – “80:80”
   links:
     – mysql
 mysql:
   image: mysql
   cpu_shares: 100
   mem_limit: 404288000
   environment:
     MYSQL_ROOT_PASSWORD: password

 

Sample YML

 

version: ‘2
services:
 mysql:
   image: ‘mysql:5.7’

   cpu_shares: 100
   mem_limit: 404288000
   environment:
     – MYSQL_ROOT_PASSWORD=secret
 php-fpm:
   image: wordpress:4.6-fpm

   cpu_shares: 100
   mem_limit: 404288000
   environment:
     – WORDPRESS_DB_USER=root
     – WORDPRESS_DB_PASSWORD=secret
   volumes:
     – ‘./data/html:/var/www/html’
 web:
   image: bcardiff/nginx-4-wordpress-fpm

   cpu_shares: 100
   mem_limit: 404288000
   environment:
     – PHP_FPM_SOCK=php-fpm:9000
   ports:
     – 8080:80
   volumes:
     – ‘./data/html:/var/www/html’

 

Terminology

Container instance – EC2 instance

Cluster – resource pool

Task definition version – code version

 

Troubleshooting

  1. Set desired count to 0 so that you can delete a ‘service’ from a cluster

 

Ecs-cli

 

Update ECS container agent before you go?

 

sudo yum install aws-cli

aws configure

aws ec2 describe-instances

 

sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest

 

sudo chmod +x /usr/local/bin/ecs-cli

 

ecs-cli configure –region us-east-1 –access-key $AWS_ACCESS_KEY_ID –secret-key $AWS_SECRET_ACCESS_KEY –cluster ecs-cli-dchang

 

ecs-cli up –keypair dchangwebmd –capability-iam –size 1 –instance-type t2.small

 

Note that dchangwebmd is imported via AWS console

 

ecs-cli compose –file hello-world.yml up

ecs-cli compose –file hello-world.yml –project-name dchang-hello up

ecs-cli compose –file hello-world.yml –project-name dchang-hello down

Note – project-name = task definition name; it will be prefixed by whatever set in .ecs/config

ecs-cli compose –file hello-world.yml –project-name dchang-hello service up (this will start container from scratch every time; data will be erased)

 

ECR

Build a docker image

 

sudo usermod -a -G docker ec2-user – enable ec2-user to run docker command

 

docker images – show what you have on the ec2 instance

docker info – show the system info

 

sudo yum install -y git

git clone https://github.com/awslabs/ecs-demo-php-simple-app

cd ecs-demo-php-simple-app

docker build -t 256428178804.dkr.ecr.us-east-1.amazonaws.com/dchang .

docker build -t dchangusc .

docker tag dchangusc:latest dchangusc

To tag a local image with name “dchangusc” and tag “latest” into the “256428178804.dkr.ecr.us-east-1.amazonaws.com” repository with “version1.0.test”:

 

aws ecr get-login –region us-east-1

 

docker tag dchangusc:latest 256428178804.dkr.ecr.us-east-1.amazonaws.com/dchangusc:latest

 

docker push 256428178804.dkr.ecr.us-east-1.amazonaws.com/dchang:latest

 

docker rmi 256428178804.dkr.ecr.us-east-1.amazonaws.com/dchangusc (remove images)

 

docker login -u AWS -p AQECAHhwm0YaISJeRtJm5n1G6uqeekXuoXXPe5UFce9Rq8/14wAAAw0wggMJBgkqhkiG9w0BBwagggL6MIIC9gIBADCCAu8GCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMxZbkRPnqs5jeF88sAgEQgIICwHbybvJc7qMmPfzs86jNTMr2w9Ovxc0haEutw58Mli/wghTmVSdkQeW8e7JnT4X3oOMJIEQePGBWKrC2ep1uo1JGx3CWNpyh0a7ydIPoatULH2g+V7sGh2ydWA0xBzW7bQppD2BR1tX3WrfhKp4Y7Agwh+P7H+txPd3mEiibv89ZIsVWMYKTgZT2NeAEJoMDcMEViYtjOk4ul+EyxeRMJRpL+P76iCPDYNVQcBcaaoXPsyHBA71qiNEgqJPCqrlKpgE5E1V9E8O+zyTLi9JVs3csqtMnud+AhqJeBrkprfqkaLffBXkDUc8meGwetmj82IF9KBdYRx7Bmuw7eXCYFAH+w2LPeJSIStoSJ/1tQFC5zjSDgAapBU34ixcG6Kx2Aj6AAxTpUxeiMpPQgM2iOKMUDG9LoDUl7jF1Pmgr57bUQResTnq2i/sGKvmQTqFanB1njdMktRx+ByxkMQ4Cd3+Dghhy4SrcVDrxxOARQGEnS9aDieGYAjLoXpWgEmXavg/HQO7CG66DprXZGNvyRrS8yj3QsXGv32eeaiTV+z+KE3BE5M0WfliSl0XpVvQSxe9SPitxbs9hhSHikTEZZgrnEKKctI4wlr4MEXBaMD6IiLFhEtEg1Ob/1V7H6YqOT1OfQTACp0+PT0WZOCsdHR9VyUd5/wttxIUN2hrutjWaT5sDet9bvfErRrVrXpDWq2mU2IudBZpNxB+qsNrpHiZkdHNoQ0FRtaa4LNAY9+83JGCVt7GxlU446bBk2fcGFbLteKCsqmt5rka+fYx7vwmTFS5XR8a9Nhalg0CiZf/4YwhekiiplOaiYl1LzeuC0Fn7Cu2g6SycF/qFuND1x15Gzu2lwU0w9eX1i9k8ZhOlT3hTgRGUzy2db7YfgiXyck+CHErKjriyQuPu20ZKLZND6KfC7B5paszwAMzr9wOx -e none https://256428178804.dkr.ecr.us-east-1.amazonaws.com

 

Sample .bash_profile

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

       . ~/.bashrc

fi

 

# User specific environment and startup programs

 

PATH=$PATH:$HOME/.local/bin:$HOME/bin

AWS_ACCESS_KEY_ID=AKIAILVHFNGW5J7JNZIA

AWS_SECRET_ACCESS_KEY=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

export PATHA AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID

 

AWS ECS CLI

aws ecs list-clusters

aws ecs list-services –cluster ecs-cli-dchang

aws ecs list-tasks –cluster ecs-cli-dchang

aws

aws ecs stop-task  –cluster ecs-cli-dchang –task 0be6c2a5-4e49-43af-9c5c-19fe247db194

 

References

http://docs.aws.amazon.com/cli/latest/reference/ecs/

http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch_alarm_autoscaling.html

 

 

  • Email to Sean 2017 budget
  • Email to cloud working group – survey, Roe and Thomas
  • Email to tech senior management at AWS conference
  • Email to Rick 2017 projects (slides, Madhura’s feedback)
  • Email to finance – 2017 budget
  • Email to Paul Mort about qa environment and CD pipeline
  • Check Madhura’s writing (load testing data)
  • Check Roger’s forms additional headcount
  • Check Madhura’s forms additional headcount – for ongoing and site performance project
  • Accomplishment table (Madhura)
  • Writing in load testing data (Madhura)
  • API testing data (Derek)
  • Real Device load testing for mobile web – requested by Mahesh. Marquee video is the use case. (Derek)
  • 2017 project table (Derek)
  • QA environment cost anaysis
  • Jacek – CI pipeline end to end

 

 

Nginx

https://gist.github.com/ericandrewlewis/95239573dc97c0e86714

 

Sample YML

image: nginx
 volumes:
  – ./mysite.template:/etc/nginx/conf.d/mysite.template
 ports:
  – “8080:80”
 environment:
  – NGINX_HOST=foobar.com
  – NGINX_PORT=80
 command: /bin/bash -c “envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g ‘daemon off;'”

 

Docker hub – https://hub.docker.com/r/bcardiff/nginx-4-wordpress-fpm/

 

Terraform vs Cloudformation

 

http://www.slideshare.net/ServNet/cloudformation-vs-terraform-vs-ansible

 

AWS solutions architect

 

  • Business logic in EC2, structured data in RDS and static content in S3

 

 

Training

 

  • AWS associate
  • AWS professional – devops engineer and solutions architect

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: