Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

[Codelab 2017] Docker 기초 및 활용 방안

578 views

Published on

2017년 11월에 진행된 Codelab 자료입니다. 강의 및 수업 진행은 모빌리스트의 변규현님입니다.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

[Codelab 2017] Docker 기초 및 활용 방안

  1. 1. 양재동 코드랩 DOCKER 기초 및 활용방안
  2. 2. Presentation URL http://bit.ly/2xNeU4K 2
  3. 3. Who made this? - Server programmer - AWSKRUG Data Science Group Member - Before - Parisien - AFI Server developer - Now - Movilest CTO - Specialized in - NodeJS, JAVA, French - MySQL, dynamodb, redis, mongodb, - Webpack, ReactJS, Redux - docker, jenkins, docker-compose, DevOps - AWS: ELB, EB, Route53, S3, CodeDeploy, Athena … etc 3 BYUN, Kyu Hyun
  4. 4. Docker is a platform 4
  5. 5. Platform? 5
  6. 6. A platform abstracts away a messy problem so you can build on top of it. - Sam Ghods, Co-Founder at Box 6https://www.youtube.com/watch?v=of45hYbkIZs&feature=youtu.be
  7. 7. Summary 1. What is docker? 2. Install kitematic 3. Run docker container using docker-cli 4. Manage docker image using Dockerfile 5. Run docker container using kitematic 6. Build multi-container environments using docker-compose 7. Run docker on AWS EC2 and Elastic Beanstalk 7
  8. 8. 1. What is docker? Everyone says that docker is a trend in micro services. Why? 8
  9. 9. 9 What is docker? - Docker is the world’s leading software container platform. - Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers. - Operators use Docker to run and manage apps side-by-side in isolated containers to get better compute density. - Enterprises use Docker to build agile software delivery pipelines to ship new features faster, more securely and with confidence for both Linux and Windows Server apps. https://www.docker.com/what- docker
  10. 10. 10 What is docker-container? - Using containers, everything required to make a piece of software run is packaged into isolated containers. - Unlike VMs, containers do not bundle a full operating system - only libraries and settings required to make the software work are needed. - This makes for efficient, lightweight, self-contained systems and guarantees that software will always run the same, regardless of where it’s deployed. https://www.docker.com/what- docker
  11. 11. 11 What is docker-container? - Package software into standardized units for development, shipment and deployment. - A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. - Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure. https://www.docker.com/what- docker
  12. 12. 12 What is docker-container? https://www.docker.com/what-container
  13. 13. 13 What is docker-container? - Comparing Containers and Virtual Machines https://www.docker.com/sites/default/files/VM%402x.png https://www.docker.com/sites/default/files/Container%402x.png
  14. 14. 14 What is docker-container? - Comparing Containers and Virtual Machines Together https://www.docker.com/what-container
  15. 15. 15 Basic docker architecture https://docs.docker.com/engine/article-img/architecture.svg
  16. 16. 16 Docker customers Source: https://d2axcg2cspgbkk.cloudfront.net/wp-content/uploads/ClusterUP-containerscape.png
  17. 17. 2. Install kitematic 17
  18. 18. 18 Kitematic Kitematic - Fast and Easy Setup - Docker Hub Integration - Seamless Experience Between CLI and GUI - Advanced Features - Automatically map ports - Visually change environment variables, configuring volumes, streamline logs and CLI access to containers https://kitematic.com/
  19. 19. 19 Kitematic
  20. 20. 20 Kitematic Docker quickstart terminal
  21. 21. 3. Run docker container using docker-cli 21
  22. 22. 22 Run docker container using docker-cli Docker Hub - Docker Hub is a cloud-based registry service which allows you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker Cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline. https://docs.docker.com/docker-hub/
  23. 23. 23 Run docker container using docker-cli https://hub.docker.com/
  24. 24. 24 Run docker container using docker-cli https://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=node&starCount=0
  25. 25. 25 Run docker container using docker-cli Useful command - docker images - docker ps -a - docker attach - docker run <option> - docker exec -it <Conatainer-Name> bash - docker build -t <username>/<image_name>:<TAG> ./ - docker commit <container> <username>/<image_name>:<TAG> https://docs.docker.com/engine/reference/commandline/cli/
  26. 26. 26 Run docker container using docker-cli Docker base command - https://docs.docker.com/engine/reference/commandline/docker/#description Example - https://gist.github.com/novemberde/238b48af0c49e8df4e0796f9182f11c6
  27. 27. 4. Manage docker image using Dockerfile 27
  28. 28. 28 Manage docker image using Dockerfile What is Dockerfile? - Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession. https://docs.docker.com/engine/reference/builder/
  29. 29. 29 Manage docker image using Dockerfile Dockerfile Instruction - FROM <image> [AS <name>] - RUN <command> - CMD command param1 param2 - LABEL <key>=<value> <key>=<value> <key>=<value> … - EXPOSE <port> [<port>/<protocol>...] - ENV <key> <value> or ENV <key>=<value> ... - ADD <src>... <dest> - COPY <src>... <dest> - ENTRYPOINT command param1 param2 - VOLUME ["/data"] - USER <user>[:<group>] or USER <UID>[:<GID>] - WORKDIR /path/to/workdir - ARG <name>[=<default value>] - ONBUILD [INSTRUCTION] https://docs.docker.com/engine/reference/builder/
  30. 30. 30 Manage docker image using Dockerfile https://github.com/nodejs/docker-node/blob/c37d5e87fa6d46c0e387f73161b056bbf90b83aa/8.6/Dockerfile
  31. 31. 31 Manage docker image using Dockerfile Build Docker image - Dockerfile FROM node MAINTAINER Novemberde "novemberde.github.io" # node 배포환경으로 변수 설정 ENV NODE_ENV production RUN npm install -g pm2 node-gyp VOLUME /var/lib/node VOLUME /root/.pm2 EXPOSE 80 443 - Make ‘.dockerignore’ file - docker build . -t test https://docs.docker.com/engine/reference/builder/
  32. 32. 32 Manage docker image using Dockerfile Dockerfile reference - https://docs.docker.com/engine/reference/builder/ Example - https://hub.docker.com/r/novemberde/docker_node_server/~/dockerfile/ - https://hub.docker.com/_/jenkins/ - https://hub.docker.com/_/redis/ - https://hub.docker.com/r/wnameless/oracle-xe-11g/ - https://hub.docker.com/_/mysql/ - https://hub.docker.com/_/mongo/
  33. 33. 5. Run docker container using kitematic 33
  34. 34. 34 Run docker container using kitematic Create MySQL https://kitematic.com/
  35. 35. 35 Run docker container using kitematic Connect to MySQL https://kitematic.com/
  36. 36. 36 Run docker container using kitematic Connect to MySQL - Set environment variables ( MYSQL_ROOT_PASSWORD=1234 ) https://kitematic.com/
  37. 37. 37 Run docker container using kitematic Connect to MySQL - Restart the docker container https://kitematic.com/
  38. 38. 38 Run docker container using kitematic Connect to MySQL - Click EXEC button - Follow the below image. https://kitematic.com/
  39. 39. 39 Run docker container using kitematic Connect to MySQL - Configure a custom port https://kitematic.com/
  40. 40. 40 Run docker container using kitematic Connect to the MySQL on a docker container using MySQL Workbench - CREATE DATABASE wordpress;
  41. 41. 41 Run docker container using kitematic Create wordpress server using docker
  42. 42. 42 Run docker container using kitematic Create wordpress server using docker
  43. 43. 43 Run docker container using kitematic Create an wordpress server using docker
  44. 44. 44 Run docker container using kitematic Create a ghost server using docker
  45. 45. 45 Run docker container using kitematic Create a tensorflow container using docker
  46. 46. 6. Build multi-container environments using docker-compose 46
  47. 47. 47 What is docker-compose? https://severalnines.com/sites/default/files/Compose.png
  48. 48. 48 What is docker-compose? - Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features. - Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in Common Use Cases. https://docs.docker.com/compose/overview/
  49. 49. 49 Build multi-container environments - Example version: "3" services: webapp: build: context: ./ dockerfile: Dockerfile ports: - "3000:3000" environment: - PORT=3000 volumes: - src:/src volumes: src:
  50. 50. 50 Build multi-container environments
  51. 51. 51 Build multi-container environments - Command line interface - docker-compose [SUBCOMMAND] --help - build - --force-rm: Always remove intermediate containers. - --no-cache: Do not use cache when building the image. - --pull: Always attempt to pull a newer version of the image. - --build-arg key=val: Set build-time variables for one service. - up - -d: start containers using daemon - down - logs - start - stop
  52. 52. 7. Run docker on AWS EC2 and Elastic Beanstalk 52
  53. 53. 53 AWS EC2 and Elastic Beanstalk - Amazon EC2 - Amazon Elastic Computing Cloud - Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction - AWS Elastic Beanstalk - An easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.
  54. 54. 54 Run docker on EC2 - Install AWS Command line interface on Local - https://aws.amazon.com/ko/cli/ - Create IAM user for the programmatic access. - https://console.aws.amazon.com/iam/home - aws configure AWS Access Key ID [****************AAAA]: AWS Secret Access Key [****************AAAA]: Default region name [ap-northeast-2]: Default output format [None]: https://docs.docker.com/machine/examples/aws/#step-2-use-machine-to-create-the- instance
  55. 55. 55 Run docker on EC2 - docker-machine create --driver amazonec2 --amazonec2-open-port 8000 -- amazonec2-region us-east-1 aws-sandbox - docker-machine ls - docker-machine inspect <machine> - docker-machine ssh aws-sandbox sudo docker container ls -a exit - docker container ls -a https://docs.docker.com/machine/examples/aws/#step-2-use-machine-to-create-the- instance
  56. 56. 56 Beanstalk
  57. 57. 57 Beanstalk
  58. 58. 58 Beanstalk
  59. 59. 59 Beanstalk
  60. 60. 60 Beanstalk - Upload new version
  61. 61. 61 Beanstalk
  62. 62. 62 References - https://www.youtube.com/watch?v=of45hYbkIZs&feature=youtu.be - https://www.docker.com/what-docker - https://kitematic.com/ - https://docs.docker.com/docker-hub/ - https://docs.docker.com/engine/reference/commandline/cli/ - https://docs.docker.com/engine/reference/builder/ - https://github.com/nodejs/docker- node/blob/c37d5e87fa6d46c0e387f73161b056bbf90b83aa/8.6/Dockerfile - https://docs.docker.com/compose/overview/ - https://docs.docker.com/machine/examples/aws/#step-2-use-machine-to-create-the- instance
  63. 63. Thanks! Any questions? You can find me at: https://novemberde.github.io https://awskrug.slack.com/ https://yjdcodelab.slack.com 63

×