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

ElasticContainerServicesハンズオン

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for tarosaiba tarosaiba
February 28, 2019

 ElasticContainerServicesハンズオン

Avatar for tarosaiba

tarosaiba

February 28, 2019
Tweet

More Decks by tarosaiba

Other Decks in Technology

Transcript

  1. @tarosaiba • Future Architect, Inc • TIG所属 4年目 • Infra

    - MW - CI 周りやってきました • AWS/GCP • Infrastructure as Codeの導入が得意 http://www.atmarkit.co.jp/ait/articles/1806/05/news010_2.html Shuntaro Saiba 2
  2. 4 私のいままで エンプラ小売り & AWS エンプラ金融 & オンプレ エンプラ小売り &

    GCP エンプラ小売り & AWS 本番環境でコンテナ運 用を経験
  3. ECS の簡単な仕組み 9 ECS Cluster EC2 EC2 Service Task Task

    ・・・ • EC2でクラスタを構成 • Task(=コンテナ)で コンテ ナイメージを指定 • ServiceでTask数を指定
  4. 今回やること 13 ECS Cluster App Source Dockerfile Image COMMIT DEPLOY

    Service Task Docker BUILD Docker PUSH AWS Service  ECR Registry 1 2 3 4
  5. 今回やること 14 No やること 内容 方法 Commit • Dockerfileと APP

    のソースコードを作成 • N/A Docker Build • Docker の Image を作成 • docker build Docker Push • Docker Imageを ECR に Push • AWS コンソール • docker push Deploy to ECS • ECR の Cluster、Service作成 • Task をデプロイ • AWS コンソール 1 2 3 4
  6. Sample Java Source • こちらのSampleプログラムを 使います。 https://github.com/spring-projects/spring-petclinic • maven で

    ビルド • jar が作成されたことを確認 17 # Git Clone > git clone https://github.com/spring-projects/spring-petclinic # Build springboot source > mvn clean install [INFO] Scanning for projects... Downloading from spring-snapshots: .. [INFO] -------------------------------------------------------------- [INFO] BUILD SUCCESS -------------------------------------------------------------- > ls target/*.jar target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar
  7. Sample Java Source • 動かしてみましょう 18 # Start Springboot >

    java -jar ./target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar
  8. Sample Dockerfile • Dockerfile を作成します • CentOS7にopenjdkをインストールし ビルド済みのjarをコンテナにコピー • ポートの公開設定をして、jarを起動

    19 # ベースのイメージを指定 FROM centos:7 # yumでJavaをInstall RUN yum update -y && \ yum install -y java-1.8.0-openjdk # 作業ディレクトリに移動 WORKDIR /app # jarをコンテナにコピー COPY ./target/spring-petclinic-xxx.jar /app # ポートの公開設定 EXPOSE 8080 # コンテナ内でmy-app.jarを実行 CMD ["java", "-jar", "/app/spring-petclinic-xxx.jar"] # Make Dockerfile at same directry > vim Dockerfile Dockerfile pom.xml readme.md src target
  9. Docker build • docker build コマンドでイメージを作 成します 23 # Check

    files > ls Dockerfile pom.xml readme.md src target # Docker build > docker build -t sample-springboot:latest . Sending build context to Docker daemon 57.15 MB Step 1/6 : FROM centos:7 ---> 1e1148e4cc2c Step 2/6 : RUN yum update -y && yum install -y java-1.8.0-openjdk ---> Running in a019ed4047fe .. Step 6/6 : CMD java -jar /app/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar ---> Running in 1444a0955841 ---> 86de299b51bc Removing intermediate container 1444a0955841 Successfully built 86de299b51bc
  10. 31 # Get docker command > (aws ecr get-login --no-include-email

    --region ap-northeast-1) docker login -u AWS -p ******************************************************************************************** ******************************************************************************************** ******************************************************************************************** ******************************************************************************************** ********* https://xxxxxxxxxxxxx3.dkr.ecr.ap-northeast-1.amazonaws.com Login Succeeded Docker login • ECRにPushするために、Login します Repogitory
  11. 32 # Get docker command > docker tag sample-springboot:latest ***.dkr.ecr.ap-northeast-1.amazonaws.com/sample-springboot:latest

    > docker images REPOSITORY TAG IMAGE ID CREATED SIZE ***.dkr.ecr.ap-northeast-1.amazonaws.com/sample-springboot latest 86de299b51bc 26 hours ago 541 MB > docker push ***.dkr.ecr.ap-northeast-1.amazonaws.com/sample-springboot:latest The push refers to a repository [***.dkr.ecr.ap-northeast-1.amazonaws.com/sample-springboot] 30d8f279a479: Pushing [======> ] 5.965 MB/44.61 MB a419c287f8fe: Pushing 1.536 kB a1474341a13e: Pushing [=> ] 7.739 MB/294.7 MB 071d8bd76517: Pushing [> ] 2.735 MB/201.8 MB Docker push • Docker buildします • ECRにPushします Repogitory