Cloud66 workshop handouts

Post on 12-Feb-2017

105 views 0 download

Transcript of Cloud66 workshop handouts

How to Deploy Web Apps with Docker containers!

Workshop Resources!

hands-on lab !Part 1!

Step1: !create DigitalOcean account !

!go to https://cloud.digitalocean.com/registrations/new !

and create a new account !!

Please use Promo Code: CLOUD66, to receive a $10 Credit. !

Step 2: !create Cloud 66 account !

!go to https://app.cloud66.com/users/sign_up !

and create a new account !

Step 3: ! create a remote

development machine !!

go to https://cloud.digitalocean.com/droplets/new!use the One-click App tab !

choose Docker 1.10.3 on 14:04choose size $40/month

region Londonpress create

you’ll get the login information mailed to you!!

Step 4: ! log into development

machine !ssh to your new server

open terminal

use the password in the DigitalOcean emailyou will be asked to change your password

$ssh root@<your ip>

Step 5:! install docker-compose !

output should be : docker-compose version: 1.6.2

$curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose$chmod +x /usr/local/bin/docker-compose$docker-compose —version

Step 6: ! fork the bakery example

and pull the code!

go to Github.comfork https://github.com/cloud66-samples/microservices_101

create a a home-directory for the app

pull the code

$mkdir /home/app$cd /home/app

$git clone https://github.com/<your github account>/microservices_101

go to the bakery/bricksandmortar folder

and change the IP address (of your new server) of the API to be used

Step 6½:! change the ip!

$vi /home/app/microservices_101/bakery/bricksandmortar/Dockerfile.development

ENV COUNTER_ADDRESS <your ip address>:8000

Step 7:! build all the images!

$ cd /home/app/microservices_101/bakery

go to the bakery folder

build all the images (takes approx. 10 minutes)

$docker-compose build

Step 8:! run the application!

!$docker-compose up -d

Step 9: ! init the datasource with

an on/off command!

create the DB

migrate the DB schema

$docker-compose run counter rake db:create

$docker-compose run counter rake db:migrate

Step 10: ! list all the running containers !

$docker ps$docker-compose ps

Step 11:! play with the demo!

!check docker-compose.yml

to find out on which port the services are running !https://docs.docker.com/compose/compose-file/ !

Step12:! show the log!

!see how the requests are coming in !

a great step for debugging !

$docker logs (docker ps for service names)$docker-compose logs [service_name]

Step 13: ! speedup baking by scaling the minions!

!place some order in the bakery shop ;-) !

scale some minions!!!!!

see how the backing is speed up !

!

$docker-compose scale [minion_service_name]=5

Step 14: ! speedup update by scaling the counter !

!$docker-compose scale counter=2

Step 15: ! speedup update by scaling the counter !

!lets scale our API !

why does it fail?

$docker-compose scale counter=2

Step 16: ! edit the work time of a minion

(language of choice) and build/restart!

edit the code and change the minion time You can edit on your local machine and push the changes to github and pull them into the

remote machine, or edit the code directly on the remote machine.after editing; rebuild the service

and restart the service

docker-compose will pickup the change

$docker-compose build minion_service_name

$docker-compose up -d minion_service_name

Step 17: ! development of a

service !stop the service !

go to the source folder of a service !look at the docker-compose.ml !

we mount the host volume. you can edit and change code and start stop when need !!!!!

edit the service and just run only the !!!!

(no need for building) !

$docker-compose stop minion_service_name

$docker-compose run minion_service_name

Step 18:! build/restart service!

done editing and debugging? build the service !!!!!

run it again!!

$docker-compose build minion_service_name

$docker-compose up -d minion_service_name

Step 19:! show memory usage !

!if you want to see how the memory is getting used: !

run memory usage!!!!!!!!

$docker stats `docker ps | awk '{print $NF}' | grep -v NAMES`

hands-on lab !Part 2!

Step 1: ! add DO as your cloud

provider !!

go to https://app.cloud66.com/clouds and add digital ocean as the cloud provider !

Step 2: ! create a new Docker

stack !go to your cloud 66 account and create a Docker stack; give the stack a name and use the service.yml in .cloud directory from

your repository!paste the service.yml in the advanced tab and hit NEXT

!

Step 3: choice cloud provider (DO) and start

deploy !run on digital ocean using region: london / 20gb / 2cpu run mysql and rabbitmq on the same server !

and hit deploy

Step 4: ! explore service.yml

during waiting!help.cloud66.com/building-your-stack/docker-service-

configuration !

Step 5: !setup DNS!

check the UI for the new IP address of your docker cluster.!

edit your /etc/hosts file to point the following URL’s ![ip_address] www.microservices101.io![ip_address] api.microservices101.io ![ip_address] cms.microservice101.io!

!!!

Step 6: !See you bakery in action !

!visit www.microservice101.io!

Step 7:! use Live Logs to see the

logs of the services!

Step 8: ! scale up the minion process for the UI !

Step 9:! install cx!

$curl -sSL https://s3.amazonaws.com/downloads.cloud66.com/cx_installation/cx_install.sh | bash

$gcx stacks list

install out CX tool belt

go to your remote development machine (not the one created with C66)

please register the tool beltcheck if you can see your new stack

scale a minion

play with scaling others and list all services:

Step 10:! scale up using CX !

$cx services scale -s [your stack] minion_bagel 5

$cx services list -s [your stack]

Step 11:! change some code of the

minion and push it to your repo !

Commit your changes and push those changes to github. !Edit the service.yml to use build grid instead of pulling

images from Docker Hub.!Build and publish only that service.!