Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker on AWS Elastic Beanstalk

Docker on AWS Elastic Beanstalk

Szymon Skórczyński

October 15, 2015
Tweet

More Decks by Szymon Skórczyński

Other Decks in Programming

Transcript

  1. DOCKER
    on
    AWS Elastic Beanstalk
    Szymon Skórczyński
    Schibsted Tech Polska
    AWS UG Tricity
    October 15, 2015

    View Slide

  2. Szymon Skórczyński
    PHP Developer
    @sskorc

    View Slide

  3. View Slide

  4. View Slide

  5. WHAT MAKES DOCKER
    SO GOOD?

    View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. View Slide

  11. Host OS
    Hypervisor
    Guest
    OS
    Guest
    OS
    Guest
    OS
    bins/libs bins/libs bins/libs
    App A App A` App B
    Host OS
    Docker
    bins/libs bins/libs
    App A
    App A’
    App B
    App B’
    App B’
    App B’
    VM
    Docker container
    Docker
    Standard VM

    View Slide

  12. View Slide

  13. View Slide

  14. IMAGE
    VS
    CONTAINER

    View Slide

  15. HOW TO DEVELOP?

    View Slide

  16. LINUX

    View Slide

  17. Host (Mac or Windows)
    Docker Client
    Docker Machine
    Docker Server
    Container
    Apache
    Container
    Mongo

    View Slide

  18. applicaction
    sources
    DB
    files

    View Slide

  19. php:
    build: .
    links: [db]
    volumes:
    - .:/var/www/docker-symfony
    nginx:
    image: nginx:1.9.4
    links: [php]
    volumes_from: [php]
    volumes:
    - ./docker/vhost.conf:/etc/nginx/conf.d/default.conf
    ports: ["80:80"]
    db:
    image: mongo:latest
    volumes:
    - /mnt/sda1/var/lib/mongo-data:/data/db
    ports: ["27017:27017"]
    docker-compose.yml

    View Slide

  20. FROM php:5.6.12-fpm
    RUN apt-get update \
    && curl -sL https://deb.nodesource.com/setup | bash - \
    && apt-get install -y git libssl-dev zlib1g-dev libicu-dev g++ \
    && pecl install mongo \
    && echo extension=mongo.so > /usr/local/etc/php/conf.d/mongo.ini \
    && pecl install apcu-beta \
    && echo extension=apcu.so > /usr/local/etc/php/conf.d/apcu.ini \
    && docker-php-ext-install zip mbstring intl
    RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/bin/composer
    ADD docker/php.ini /usr/local/etc/php/php.ini
    WORKDIR /var/www/docker-symfony
    Dockerfile

    View Slide

  21. FROM sskorc/symfony2-mongo:latest
    ADD docker/php.ini /usr/local/etc/php/php.ini
    WORKDIR /var/www/docker-symfony
    Dockerfile

    View Slide

  22. RUN IT!
    docker-compose up -d

    View Slide

  23. DEMO

    View Slide

  24. HOW TO DEPLOY?

    View Slide

  25. View Slide

  26. THE STEPS
    1. Create a specific IAM policy and assing it to the role
    2. Create a new environment with “Multi-container Docker”
    predifined configuration

    View Slide

  27. THE STEPS
    1. Create a specific IAM policy and assing it to the role
    2. Create a new environment with “Multi-container Docker”
    predifined configuration

    View Slide

  28. THE STEPS
    1. Create a specific IAM policy and assing it to the role
    2. Create a new environment with “Multi-container Docker”
    predifined configuration
    3. Assign a proper role to the environment

    View Slide

  29. THE STEPS
    1. Create a specific IAM policy and assing it to the role
    2. Create a new environment with “Multi-container Docker”
    predifined configuration
    3. Assign a proper role to the environment

    View Slide

  30. THE STEPS
    1. Create a specific IAM policy and assing it to the role
    2. Create a new environment with “Multi-container Docker”
    predifined configuration
    3. Assign a proper role to the environment
    4. Prepare the Dockerrun.aws.json file
    5. Deploy!

    View Slide

  31. {
    "AWSEBDockerrunVersion": 2,
    "authentication": {
    "bucket": "docker-symfony",
    "key": "docker/dockercfg"
    },
    "volumes": [
    {
    "name": "data",
    "host": { "sourcePath": "/var/data" }
    },
    {
    "name": "symfony-app",
    "host": { "sourcePath": "/var/app/current" }
    },
    {
    "name": "vhost-config",
    "host": { "sourcePath": "/var/app/current/docker/vhost.conf" }
    }
    ],

    View Slide

  32. "containerDefinitions": [{
    "name": "db",
    "image": "mongo:latest",
    "essential": true,
    "memory": 256,
    "mountPoints": [{
    "sourceVolume": "data",
    "containerPath": "/data/db"
    }]
    },
    {
    "name": "php",
    "image": "sskorc/docker-symfony:latest",
    "essential": true,
    "memory": 256,
    "links": ["db"],
    "mountPoints": [{
    "sourceVolume": "symfony-app",
    "containerPath": "/var/www/docker-symfony"
    }]
    },

    View Slide

  33. {
    "name": "nginx",
    "image": "nginx:1.9.4",
    "essential": true,
    "memory": 256,
    "portMappings": [{
    "hostPort": 80,
    "containerPort": 80
    }],
    "links": ["php"],
    "mountPoints": [{
    "sourceVolume": "symfony-app",
    "containerPath": "/var/www/docker-symfony"
    },
    {
    "sourceVolume": "vhost-config",
    "containerPath": "/etc/nginx/conf.d/default.conf"
    }]
    }
    ]
    }
    Dockerrun.aws.json

    View Slide

  34. option_settings:
    - namespace: aws:elasticbeanstalk:command
    option_name: Timeout
    value: 1200
    commands:
    01_docker_clean_containers:
    command: docker rm -v $(docker ps -a -q)
    ignoreErrors: true
    02_docker_clean_images:
    command: docker rmi $(docker images -q)
    ignoreErrors: true
    .ebextensions/01docker.config

    View Slide

  35. checkout
    sources
    push
    sf2 image
    pull
    sf2 image
    mongo image
    nginx image
    GitHub
    CircleCI
    AWS
    Docker Hub
    build sf2 image
    run tests
    on sf2 image
    send
    and fire!
    pull
    mongo image
    run
    sf2 image
    mongo image
    nginx image

    View Slide

  36. checkout
    sources
    push
    sf2 image
    pull
    sf2 image,
    mongo image,
    nginx image
    GitHub
    CircleCI
    AWS
    Docker Hub
    build
    run tests
    on
    send sources
    and fire!
    pull
    mongo image
    run
    sf2 image,
    mongo image,
    nginx image

    View Slide

  37. checkout
    sources
    push
    sf2 image
    pull
    sf2 image,
    mongo image,
    nginx image
    GitHub
    CircleCI
    AWS
    Docker Hub
    build
    run tests
    on
    send sources
    and fire!
    pull
    mongo image
    run
    sf2 image,
    mongo image,
    nginx image
    APPLICATION_VERSION=$ENVIRONMENT-$BUILD_NUM-docker-symfony.zip
    zip $APPLICATION_VERSION -r .
    aws s3 cp $APPLICATION_VERSION s3://$EB_BUCKET/$APPLICATION_VERSION
    aws elasticbeanstalk create-application-version --application-name
    "docker-symfony" \
    --version-label $BUILD_NUM --source-bundle S3Bucket=
    $EB_BUCKET,S3Key=$APPLICATION_VERSION
    aws elasticbeanstalk update-environment --environment-name
    $ENVIRONMENT \
    --version-label $BUILD_NUM

    View Slide

  38. checkout
    sources
    push
    sf2 image
    pull
    sf2 image,
    mongo image,
    nginx image
    GitHub
    CircleCI
    AWS
    Docker Hub
    build sf2 image
    run tests
    on sf2 image
    send sources
    and fire!
    pull
    mongo image
    run
    sf2 image,
    mongo image,
    nginx image

    View Slide

  39. WRAP UP

    View Slide

  40. SHOULD YOU TRY DOCKER?

    View Slide

  41. WHY?
    Portability
    Isolation
    Performance
    Modularity
    Community

    View Slide

  42. https://github.com/sskorc/docker-symfony
    http://www.schibsted.pl/category/devops/
    @sskorc

    View Slide