0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS EC2にDockerでDocker Compose(1.29.2)を導入

Last updated at Posted at 2021-06-19

#目的
AWS環境にEC2インスタンスを立て、Dockerを利用してRedmine, Gitlab, Jenkinsの環境セットを
繰り返し構築できるように、実際に試してみた内容を残しておきます。
(備忘録も込めて実行時のログも記載しているため、見にくい部分ありましたらご容赦ください)

#記載範囲
下記前提条件に沿って、EC2インスタンスを立てた後にDockerを導入してDocker Composeが利用できるところまでを記載します。

試すにあたり、以下サイトを参考にさせて頂きました。
AWS EC2にDockerでRedmineを導入

#前提条件

  • EC2インスタンスは以下で作成
    • プラットフォーム:Amazon Linux
    • インスタンスタイプ:t2-medium ※後にGitlabを導入を見越しての選択(この記事の範囲であれば、特にt2.microでも問題なし)
    • docker-compose(執筆時点の最新1.29.2)
  • EC2インスタンスはTeraTermからSSH接続してDockerコマンドを実行(SSH接続方法はここでは割愛)
  • ec2-userにて実行

#最新パッケージの最新化
AWS EC2にインストールされている各モジュールを最新化しておきます。

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo yum update -y
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
No packages marked for update

#Dockerの導入

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo yum install -y docker
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:20.10.4-1.amzn2 will be installed
--> Processing Dependency: runc >= 1.0.0 for package: docker-20.10.4-1.amzn2.x86_64
--> Processing Dependency: libcgroup >= 0.40.rc1-5.15 for package: docker-20.10.4-1.amzn2.x86_64
--> Processing Dependency: containerd >= 1.3.2 for package: docker-20.10.4-1.amzn2.x86_64
--> Processing Dependency: pigz for package: docker-20.10.4-1.amzn2.x86_64
--> Running transaction check
---> Package containerd.x86_64 0:1.4.4-1.amzn2 will be installed
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
---> Package pigz.x86_64 0:2.3.4-1.amzn2.0.1 will be installed
---> Package runc.x86_64 0:1.0.0-0.3.20210225.git12644e6.amzn2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package    Arch   Version                              Repository         Size
================================================================================
Installing:
 docker     x86_64 20.10.4-1.amzn2                      amzn2extra-docker  32 M
Installing for dependencies:
 containerd x86_64 1.4.4-1.amzn2                        amzn2extra-docker  24 M
 libcgroup  x86_64 0.41-21.amzn2                        amzn2-core         66 k
 pigz       x86_64 2.3.4-1.amzn2.0.1                    amzn2-core         81 k
 runc       x86_64 1.0.0-0.3.20210225.git12644e6.amzn2  amzn2extra-docker 3.2 M

Transaction Summary
================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 59 M
Installed size: 243 M
Downloading packages:
(1/5): pigz-2.3.4-1.amzn2.0.1.x86_64.rpm                   |  81 kB   00:00
(2/5): libcgroup-0.41-21.amzn2.x86_64.rpm                  |  66 kB   00:00
(3/5): containerd-1.4.4-1.amzn2.x86_64.rpm                 |  24 MB   00:01
(4/5): runc-1.0.0-0.3.20210225.git12644e6.amzn2.x86_64.rpm | 3.2 MB   00:00
(5/5): docker-20.10.4-1.amzn2.x86_64.rpm                   |  32 MB   00:01
--------------------------------------------------------------------------------
Total                                               33 MB/s |  59 MB  00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : runc-1.0.0-0.3.20210225.git12644e6.amzn2.x86_64              1/5
  Installing : containerd-1.4.4-1.amzn2.x86_64                              2/5
  Installing : libcgroup-0.41-21.amzn2.x86_64                               3/5
  Installing : pigz-2.3.4-1.amzn2.0.1.x86_64                                4/5
  Installing : docker-20.10.4-1.amzn2.x86_64                                5/5
  Verifying  : containerd-1.4.4-1.amzn2.x86_64                              1/5
  Verifying  : docker-20.10.4-1.amzn2.x86_64                                2/5
  Verifying  : pigz-2.3.4-1.amzn2.0.1.x86_64                                3/5
  Verifying  : runc-1.0.0-0.3.20210225.git12644e6.amzn2.x86_64              4/5
  Verifying  : libcgroup-0.41-21.amzn2.x86_64                               5/5

Installed:
  docker.x86_64 0:20.10.4-1.amzn2

Dependency Installed:
  containerd.x86_64 0:1.4.4-1.amzn2
  libcgroup.x86_64 0:0.41-21.amzn2
  pigz.x86_64 0:2.3.4-1.amzn2.0.1
  runc.x86_64 0:1.0.0-0.3.20210225.git12644e6.amzn2

Complete!

#Dockerサービスを起動

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo service docker start
Redirecting to /bin/systemctl start docker.service

#Docker Compose(執筆時点の最新:1.29.2)の導入
sudoコマンドにて、スーパーユーザ(rootユーザ)の管理者権限で実行します。

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo su
[root@ip-xxx-xx-xx-xxx ec2-user]# curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   633  100   633    0     0   2813      0 --:--:-- --:--:-- --:--:--  2813
100 12.1M  100 12.1M    0     0  4352k      0  0:00:02  0:00:02 --:--:-- 5178k
[root@ip-xxx-xx-xx-xxx ec2-user]# chmod +x /usr/local/bin/docker-compose

#docker groupにec2-userを紐づける
ec2-userでdockerコマンドやdocker-composeコマンド実行時に権限エラーとならないように必要のようです。

[ec2-user@ip-xxx-xx-xx-xxx ~]$ sudo su
[root@ip-xxx-xx-xx-xxx ec2-user]# grep -i docker /etc/group
docker:x:992:
[root@ip-xxx-xx-xx-xxx ec2-user]# sudo gpasswd -a ec2-user docker
Adding user ec2-user to group docker
[root@ip-xxx-xx-xx-xxx ec2-user]# grep -i docker /etc/group
docker:x:992:ec2-user

#次回コンテナ作成用にディレクトリを作成
次回はDocker Composeを利用してRedmineを導入するため、docker-compose.ymlの作成から記載する予定です。

[ec2-user@ip-xxx-xx-xx-xxx container01]$ pwd
/home/docker/container01

#Dockerのバージョン確認
今回導入したDockerのバージョンを確認。

[ec2-user@ip-xxx-xx-xx-xxx container01]$ docker --version
Docker version 20.10.4, build d3cb89e

#Docker Composeのバージョン確認
今回導入したDocker Composeのバージョンを確認。

[ec2-user@ip-xxx-xx-xx-xxx container01]$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?