はじめに
この記事ではAWSのAmazon Linux2を使用して次のことを実行します。
1. dockerのインストール
2. docker imageであるcentosを起動する
3. 2で起動したコンテナ内でpython3をインストール
1. dockerのインストール
まず以下のようにyumのアップデートを行います。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo yum update -y
次にdockerをインストールします。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo amazon-linux-extras install docker -y
インストールが完了したら、docker daemonを起動します。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo service docker start
ec2-userをdockerグループに追加します。
これは必須ではないですが、以降sudo
なしでdocker
コマンドが使用できます。
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo usermod -a -G docker ec2-user
上記コマンドを実行したら、一度ターミナルを閉じます。その後再度接続し直します。
2. centosを起動する
まずrun
コマンドによってコンテナを起動します。イメージのプルがされていない場合、プルをしてから起動することができます。
オプション-it
により、起動したコンテナの中に入ることができます。
(・・・は表示されるメッセージを省略して書いています)
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ docker run -it centos
・
・
・
[root@xxx /]#
3. コンテナ内でpython3をインストール
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ yum install python3 -y
以下のようにpython3
コマンドを入力することで対話モードになり、インストールされたことがわかります。
[root@xxx /]# python3
Python 3.6.8 (default, Apr 16 2020, 01:36:27)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
インストール後はpip3
コマンドを使用し、必要なパッケージのインストールを行うことができます。
次のコマンドでaws-cliのバージョン1をインストールしています。
[root@xxx /]# pip3 install awscli
参考記事
- AWS 公式サイト https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/docker-basics.html
- CentOS7 に pip と awscli をインストール https://rriifftt.hatenablog.com/entry/2015/10/28/142043