LoginSignup
1
0

More than 3 years have passed since last update.

Python3系のAWS CLIと.NET Core v2.1の入ったCentOSイメージを作る

Last updated at Posted at 2019-12-24

背景

仕事で.NET Coreのソフトをコンテナ化する機会があったので、そのまとめとPython2系が2020年1月1日に廃止されるので、Python3系の導入についても触れていこうと思います。

二番煎じかもしれませんが、ご了承ください。

内容

以下の構成でDockerのイメージを作成します。

  • baseImage : CentOS
  • Python 3系
  • .NET Core v2.1

導入

(1) DockerfileをClone

まず、以下のリポジトリをクローンしてください。

# ファイルをClone
$ git clone https://github.com/susu-to-susu/Dockerfile_aws_dotnet.git

(2)イメージの作成

Dockerfileの場所まで移動して、buildしてイメージを作成してください。

# ディレクトリ移動
$ cd Dockerfile_windows_dotnet

# イメージの作成
$ docker build -t dotnet_aws .

(3)コンテナの作成

以下のコマンドでコンテナを作成します。

# コンテナの作成
$ docker run --name dotnet_aws -itd dotnet_aws bash

(4)動作確認

以下のコマンドでコンテナにログインをしてaws-cliとdotnetCoreの確認をします。

# アタッチ(ログイン)
$ docker attach dotnet_aws

[root@eb395ae3adad /]# dotnet --version
2.1.509
[root@eb395ae3adad /]# aws --version
aws-cli/1.16.305 Python/3.6.8 Linux/4.9.184-linuxkit botocore/1.13.41

解説

Dockerfileの中身は以下のようになっています。

# Sample Dockerfile

# Indicates that the centos image will be used as the base image.
FROM centos:latest

# Install Python
RUN yum update -y
RUN yum upgrade -y
RUN yum install -y wget
RUN yum install -y python3

# AWS CLI Settings
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py

# Install awscli
# RUN pip install awscli
RUN pip3 install awscli --upgrade --user
ENV PATH $PATH:/root/.local/bin

# Metadata indicating an image maintainer.
LABEL maintainer="susu-susu@github.com"

# dotnet Core v2.1
RUN yum install -y dotnet-sdk-2.1

やっていることは非常に簡単で、python3とdotnetCore v2.1をyumでインストールしています。

ENV PATH $PATH:/root/.local/bin

ここで気を付けることは、pip3でaws-cliをインストールした場合、デフォルトでは/root/.local/binにコマンドが格納されるのですが、環境変数に$PATHが適応されてません。少なくとも自分がやった時はそうでした。

そのため、ENVに書く必要があります。

ターゲットとしては、dotnetCoreをWindows以外で利用したい。コンテナ化して使いたいって場合に最適です。

何か誤字脱字ありましたら、ご指摘頂けると幸いです。

参考リンク

1
0
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
1
0