name: exercises-unix class: title, smokescreen, shelf, no-footer # 第13回 Unix演習<br><small>今回は無し</small> <div class=footnote> <small><small> </small></small> </div> --- name: exercises-aws class: title, smokescreen, shelf, no-footer # 第13回 AWS演習<br><small>EC2上にdockerをインストールする</small> <div class=footnote> <small><small> </small></small> </div> --- class: compact # おしながき <div class=footnote> <small><small> 次頁から手順書です </small></small> </div> 1. EC2のDebian GNU/Linuxにdockerをインストールし 1. 動作確認をしてみます - 今回は例題だけです。一緒にやります。 - 今回は、ここまでですが、 次回は、 (a)コンテナでWWWサーバを立ててみること、 (b)自分でコンテナを作成する体験を予定しています <!-- section-begin aws.ec2.install.docker --> --- class: title, smokescreen, shelf, no-footer # <small>EC2上にdockerをインストールする</small> <div class=footnote> <small><small> </small></small> </div> --- class: compact # dockerをインストールする(1): 準備の準備(1) <small> - まずはOSを最新にアップグレードし ``` $ sudo apt update $ sudo apt upgrade -y ``` </small> --- class: compact # dockerをインストールする(2): 準備の準備(2) <small> - dockerに必要なパッケージをインストールします ``` $ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y ``` - 40個くらいのパッケージがインストールされると思いますが、それで正常です </small> --- class: compact # dockerをインストールする(3): docker社の公開鍵を取得 <small> - dockerはDebianの標準パッケージではないので、 (このあとインストールする)パッケージを認証するための公開鍵をdocker社のウエブからダウンロードし、 apt-keyコマンドで鍵を登録します - 公開鍵のインストール後には、鍵のハッシュが正しいか?を確認します <br> `sudo apt-key fingerprint 0EBFCD88`を実行すると、 2017年にDocker社が作成したRSAの鍵だと表示されます ``` # 公開鍵のインストール $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # 公開鍵の確認 $ sudo apt-key fingerprint 0EBFCD88 Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ unknown] Docker Release (CE deb) <docker@docker.com> sub rsa4096 2017-02-22 [S] ``` </small> --- class: compact # dockerをインストールする(4a): パッケージを登録 <div class=footnote> <small><small> (脚注) DebianのコードネームはPixerのトイ・ストーリーのキャラクタ。 第2代リーダBruce Perenseが当時Pixerに勤めていたから:-) </small></small> </div> <small> - dockerはDebian非公式のパッケージなので、デフォルトのaptコマンドでは操作できません - dockerパッケージの配布情報をadd-apt-repositoryコマンドで登録します <br> 次のコマンドを実行してください ``` $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian bookworm stable" ``` - ちなみに bookworm はDebian 12の開発コードネーム、stableは安定版という意味です </small> --- class: compact # dockerをインストールする(4b): パッケージを登録 <div class=footnote> <small><small> </small></small> </div> <small> ``` [実行例] $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian bookworm stable" Repository: 'deb [arch=amd64] https://download.docker.com/linux/debian bookworm stable' Description: Archive for codename: bookworm components: stable More info: https://download.docker.com/linux/debian Adding repository. Press [ENTER] to continue or Ctrl-c to cancel. ``` - ENTERを押してください。パッケージ情報のインストールが始まります </small> --- class: compact # dockerをインストールする(4c): パッケージを登録 <small> ``` [実行例] (前ページの続き) Adding deb entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_debian-bookworm.list Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_debian-bookworm.list Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [38 B] ... 省略 ... Get:9 https://cdn-aws.deb.debian.org/debian bookworm/main amd64 DEP-11 Metadata [4492 kB] Fetched 4599 kB in 2s (2144 kB/s) Reading package lists... Done W: https://download.docker.com/linux/debian/dists/bookworm/InRelease: ... 省略 ... ``` - `/etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_debian-bookworm.list`が作成されました - これで、すべての前準備が終わり、aptコマンドで操作できるようになりました </small> --- class: compact # dockerをインストールする(5): docker-ceをインストール <small> - apt コマンドで docker-ce (docker community edition) をインストールします ``` $ sudo apt update $ sudo apt install docker-ce docker-ce-cli containerd.io -y [実行例] admin@ip-172-31-33-222:~$ sudo apt install docker-ce docker-ce-cli containerd.io -y Reading package lists... Done Building dependency tree... Done Reading state information... Done ... 省略 ... Need to get 134 MB of archives. After this operation, 516 MB of additional disk space will be used. Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [38 B] ... 省略 ... Processing triggers for man-db (2.11.2-2) ... Processing triggers for libc-bin (2.36-9+deb12u3) ... ``` </small> --- class: compact # dockerの動作確認(1): docker ps <small> - docker psを実行して、とりあえずエラーとか言われないことを確認しましょう ``` $ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ``` - `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES`はヘッダ行です - 何もコンテナが走っていないので、意味のある情報は表示されません。それで正解です </small> --- class: compact # dockerの動作確認(2): Hello from Docker! <small> - まずは定番の「hello world」のdocker版を実行してみましょう。Hello from Docker!と出ましたか? ``` [実行例] admin@ip-172-31-33-222:~$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. 〜省略〜 https://docs.docker.com/get-started/ ``` </small> <!-- section-end aws.ec2.install.docker -->