0
1

More than 3 years have passed since last update.

docker centosでpython3をインストールする方法

Last updated at Posted at 2020-09-27

はじめに

この記事では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

参考記事

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1