Docker on AWS

Zak B. Elep

Created: 2016-08-23 Tue 17:04

https://github.com/zakame/docker-eb-demo

About Me

  • @zakame in GitHub, Twitter, FB
  • Co-Founder, Chief Architect, YOYO Holdings
  • Recovering Sysadmin
  • Hacks on Perl, Docker, Emacs, Android

What's this for?

  • Short intro on using Docker on AWS via Elastic Beanstalk
  • Assumes some familiarity with Docker ecosystem
  • Assumes some familiarity with AWS infra (EC2/S3, ELB, Beanstalk)

Why Docker on Elastic Beanstalk?

  • Distribution
  • Maintenance
  • Development

Distribution

  • Software systems as containers
  • (Mostly) standalone systems (especially for exotic setups)
  • (Mostly) less chance of incompatibilities/inconsistencies

Maintenance

  • Growing from "pet to cattle" setups
  • Reducing moving targets (e.g. external dependencies)
  • Redundancy (e.g. eb swap, ELB)

Development

  • Builds up on distribution and maintenance merits
  • Correlate code history with system history (e.g. git vs docker commits)
  • Leverage other AWS solutions (e.g. RDS, Lambda)

Demo: Cat GIFs!

http://cats.zakame.org

See github above ;)

Point to Elastic Beanstalk DNS

dig +short cats.zakame.org.
zakame-cats-prod.us-east-1.elasticbeanstalk.com.
54.225.221.170
50.17.210.230

A Simple Perl app

use Plack::Builder;

my @images = <DATA>;

# Its dangerous, take a cat with you!
builder {
    mount '/' => builder {
        enable 'TMT',
            include_path => 'tmpl',
            macro => +{
                url => sub { $images[int rand @images] },
            };
    };
};

__DATA__
http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26388-1381844103-11.gif
http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr01/15/9/anigif_enhanced-buzz-31540-1381844535-8.gif
http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26390-1381844163-18.gif

A Simple Dockerfile

# our base image
FROM perl:5.24.0

# install Carton
RUN cpanm Carton

# install CPAN modules needed by the Perl app
COPY cpanfile* /usr/src/app/
WORKDIR /usr/src/app
RUN carton install --deployment

# copy files required for the app to run
COPY app.psgi /usr/src/app
COPY tmpl/index /usr/src/app/tmpl/

# tell the port number the container should expose
EXPOSE 5000

# run the application
CMD ["carton", "exec", "plackup", "app.psgi"]

Elastic Beanstalk setup

pip install awsebcli
eb init
eb create --cname zakame-cats-live blue
eb status blue
Environment details for: blue
  Application name: docker-eb-demo
  Region: us-east-1
  Deployed Version: app-160823_160301
  Environment ID: e-qmphs33nch
  Platform: 64bit Amazon Linux 2016.03 v2.1.3 running Docker 1.11.1
  Tier: WebServer-Standard
  CNAME: zakame-cats-prod.us-east-1.elasticbeanstalk.com
  Updated: 2016-08-23 08:15:08.455000+00:00
  Status: Ready
  Health: Green
eb ssh blue

Blue-green setup

eb clone --cname zakame-cats-test blue --clone_name green
eb status green
eb swap

EB Dashboard

https://console.aws.amazon.com/elasticbeanstalk

Gotchas

More Information

Finis

tumblr_li7qqi3qDc1qcn249o1_400.gif