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

タツノコハイツ DockerHandsOn

Avatar for pypypyo14 pypypyo14
January 20, 2020

タツノコハイツ DockerHandsOn

Avatar for pypypyo14

pypypyo14

January 20, 2020
Tweet

More Decks by pypypyo14

Other Decks in Technology

Transcript

  1. ## はじめまして name: おさじ (@pypypyo14) - AWSパートナーの会社でテクニカルサポート職 - ベースはインフラエンジニア -

    気軽に質問・ツッコミお願いします! 本日不参加です。。 あおいさん、よろしくおねがいします!!!!
  2. ## もくじ - Docker概要 - Hello Worldその前に - Hello World

    - Docker ContainerとDocker Image - Dockerfile - まとめ - ハンズオン! : 座学的なやつ : 一緒に手を動かしましょう
  3. ## What is Docker? - 「コンテナ」と呼ばれる仮想環境上のアプリケーションを 「開発」「共有」「実行」するためのプラットフォーム ## . ##

    ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/
  4. ## What is Docker? - 「コンテナ」と呼ばれる仮想環境上のアプリケーションを 「開発」「共有」「実行」するためのプラットフォーム - 軽量で素早い実行 -

    アプリと実行環境をコンテナに詰めて、まるっと簡単に持ち運び ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/
  5. ## What is Docker? - 「コンテナ」と呼ばれる仮想環境上のアプリケーションを 「開発」「共有」「実行」するためのプラットフォーム - 軽量で素早い実行 -

    アプリと実行環境をコンテナに詰めて、まるっと簡単に持ち運び - 開発、テスト、デプロイ それぞれにかかる時間を短縮 ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/
  6. ## Docker概要まとめ - 「コンテナ」と呼ばれる仮想環境上のアプリケーションを 「開発」「共有」「実行」するためのプラットフォーム - 軽量で素早い実行 - アプリとインフラをコンテナに詰めて、まるっと簡単に持ち運び -

    開発、テスト、デプロイ それぞれにかかる時間を短縮 ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/
  7. ## Hello world ごいっしょに インターネットで共有されているHello world用コンテナを、 手元で実行してみましょう! $ docker run

    hello-world 新しいコンテナを起動・実行するコマンド $ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  8. ## Hello world $ docker run hello-world Unable to find

    image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:d1668a9a1f5b42ed3f46b70b9cb7c88fd8bdc8a2d73509bb0041cf436018fbf5 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. (略)
  9. ## Hello world $ docker run hello-world Unable to find

    image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:d1668a9a1f5b42ed3f46b70b9cb7c88fd8bdc8a2d73509bb0041cf436018fbf5 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. (略) コンテナイメージのダウンロード(※ 既にローカルにイメージがある場合は出ない)
  10. ## Hello world $ docker run hello-world Unable to find

    image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:d1668a9a1f5b42ed3f46b70b9cb7c88fd8bdc8a2d73509bb0041cf436018fbf5 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. (略) アプリケーション「 Hello world」の実行結果
  11. ## 何が起こった? Hello from Docker! This message shows that your

    installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
  12. ## 何が起こった? 1. Docker ClientがDocker Daemonにリクエスト 2. Daemonが “hello-world”というイメージをDocker Hubからpull

    3. Daemonがイメージを元に新しいコンテナを作成 4. Daemonがコンテナの出力をClientの端末にストリーミング
  13. ## Docker ContainerとDocker Image - Dockerコンテナ - Dockerイメージをもとに作られるアプリケーション実行環境 - 「停止」「起動」「一時停止」などの状態がある

    - 書き込みOK⭕ - Dockerイメージ - コンテナを実行するため必要なファイルの実体などを含むもの (ファイルシステム) - Dockerレジストリと呼ばれるイメージ置き場を介して他人と共有することが可能 - 作成方法(ハンズオンでやりましょう ) - $ docker commit コマンドを使う - Dockerfileを書いてBuildする - 書き込みNG
  14. ## Dockerコンテナの確認 $ docker ps -a $ docker ps -a

    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dba1b03834f1 hello-world "/hello" 9 seconds ago Exited (0) 7 seconds ago hoge_fuga コンテナの一覧を表示するコマンド $ docker ps [OPTIONS] (-aはすべてのコンテナを表示するオプション )
  15. ## Dockerコンテナの確認 $ docker ps -a さっき起動したコンテナが存在している(Existed(0)) $ docker ps

    -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dba1b03834f1 hello-world "/hello" 9 seconds ago Exited (0) 7 seconds ago hoge_fuga コンテナの一覧を表示するコマンド $ docker ps [OPTIONS] (-aはすべてのコンテナを表示するオプション )
  16. ## Dockerコンテナの確認 $ docker run hello-world をもう一度行ってから $ docker ps

    -a すると、、 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9101db8ca25a hello-world "/hello" 16 seconds ago Exited (0) 14 seconds ago piyo_poyo dba1b03834f1 hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago hoge_fuga
  17. ## Dockerコンテナの確認 $ docker run hello-world をもう一度行ってから $ docker ps

    -a すると、、 コンテナが増えている IMAGEが共通のCONTAINERが別々にできる $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9101db8ca25a hello-world "/hello" 16 seconds ago Exited (0) 14 seconds ago piyo_poyo dba1b03834f1 hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago hoge_fuga
  18. ## Dockerイメージの確認 $ docker images Docker Hostに存在するイメージ一覧が確認できます $ docker images

    REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest fce289e99eb9 12 months ago 1.84kB イメージの一覧を表示するコマンド $ docker images [OPTIONS] [REPOSITORY[:TAG]]
  19. ## Dockerfile? サンプル: hello-worldコンテナのDockerfile https://github.com/docker-library/hello-world/tree/master/arm64v8/hello-world 1: FROM scratch 2: COPY

    hello / 3: CMD ["/hello"] hello-world/ ├── Dockerfile └── hello(binary) FROM: ベースとなるDockerイ メージを指定 https://hub.docker.com/_/scratch scratchは何も含まない、 空っぽのイメージ
  20. ## Dockerfile? サンプル: hello-worldコンテナのDockerfile https://github.com/docker-library/hello-world/tree/master/arm64v8/hello-world 1: FROM scratch 2: COPY

    hello / 3: CMD ["/hello"] hello-world/ ├── Dockerfile └── hello(binary) COPY: ローカルのファイルを Dockerイメージにコピー Dockerfileと同じ階層の hello を / にコピー
  21. ## Dockerfile? サンプル: hello-worldコンテナのDockerfile https://github.com/docker-library/hello-world/tree/master/arm64v8/hello-world 1: FROM scratch 2: COPY

    hello / 3: CMD ["/hello"] hello-world/ ├── Dockerfile └── hello(binary) CMD: コンテナ実行時に実行 するコマンドを指定 2行目でコピーした /hello を実行
  22. ## Dockerfileの命令 https://docs.docker.com/engine/reference/builder/ - イメージを構成するための命令を順番に書き込む - FROM, COPY, COMMANDの他にも色々なコマンドがあります -

    RUN: build中に実行するコマンドを指定 - RUN apt-get install xxx などコンテナ起動前に済ませておきたいこと - ENV: 環境変数を設定 - ENV env = development - EXPOSE: コンテナがlistenしたいネットワークポートを指定する - EXPOSE 80/tcp
  23. ## つくってみよう - 新規ディレクトリの中で、Dockerfile という名前のファイルを作成 - 以下の様に編集 - $ docker

    build --tag myimage:v1 . でビルド - $ docker run myimage:v1 でビルドしたイメージを実行 1: FROM ubuntu:latest 2: CMD [ "echo", "任意のテキスト" ]
  24. ## 作ってみよう $ docker build --tag myimage:v1 . Sending build

    context to Docker daemon 2.048kB Step 1/2 : FROM ubuntu:latest ---> 549b9b86cb8d Step 2/2 : CMD [ "echo", "任意のテキスト" ] ---> Using cache ---> 9e08c10717e7 Successfully built 9e08c10717e7 Successfully tagged myimage:v1 $ docker run myimage:v1 任意のテキスト
  25. ## Dockerレジストリ - 作成したDockerイメージはDockerレジストリと呼ばれる場所で共有可能 - DockerHub - https://hub.docker.com/ - Docker社が運営。DockerHostがデフォルトで見に行くレジストリ。

    - DockerHub以外 - Amazon ECR - Google Cloud Container Registory - Azure Container Registry - 個人構築も可能 - 提供元のはっきりしないイメージは特に セキュリティ面に注意
  26. ## Dockerレジストリを利用したDocker利用の流れ registory docker-host docker-client Dockerfile $ docker push [OPTIONS]

    NAME[:TAG] コンテナ イメージ イメージ ビルドしたDockerイメージをレジストリにpush
  27. ## Dockerレジストリを利用したDocker利用の流れ registory docker-host docker-client $ docker pull [OPTIONS] NAME[:TAG|@DIGEST]

    コンテナ イメージ イメージ Dockerレジストリのイメージをpull/create/start(run)