EC2-RHEL8にdockerとdocker-compose環境を作る時のメモ
最初に
こんにちは。しょうです。
最近、自分のWebサイトを作りたいなと思って色々
思考を巡らせています。
自分のサイトを作る為に、Djangoの理論理解をしていたり、
OSS-DB silverやHTML5 Level1取得の為の学習を通じて論理武装を
していたりするのですが、ちょっと手を動かしていきたいなという
焦りをふつふつと感じ。。。
AWS EC2+docker(docker-compose)+python(Django)+PostgreSQL
で作っていこうかなと見切り発車をしてしまいました。
dockerを挟まなくても良い気はするのですが、
単純な技術的興味と、万が一ホストをEC2ではない他の
ホストにするときに移行しやすいかなと思ってです。
この辺りは触ってみて運用してみて初めて分かるのかなと汗
今回はAWS上にRHEL8仮想サーバを立てている状態で、
そこにdockerとdocker-compose環境を構築する手順をメモって
行きたいと思います。
環境構築メモ
とりあえずuname -a
[ec2-user@ip-10-0-1-12 ~]$ uname -a
Linux ip-10-0-1-12.ap-northeast-1.compute.internal 4.18.0-305.el8.x86_64 #1 SMP Thu Apr 29 08:54:30 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux
dockerはインストールされていない模様
[ec2-user@ip-10-0-1-12 ~]$ docker --help
-bash: docker: command not found
dnfでdocker用のリポジトリを追加して内容確認
[root@ip-10-0-1-4 ~]# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
[root@ip-10-0-1-4 ~]#
[root@ip-10-0-1-4 ~]# dnf repolist -v
Loaded plugins: AmazonID, builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, groups-manager, needs-restarting, playground, product-id, repoclosure, repodiff, repograph, repomanage, reposync, subscription-manager, uploadprofile
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
DNF version: 4.4.2
cachedir: /var/cache/dnf
Docker CE Stable - x86_64 107 kB/s | 14 kB 00:00
Red Hat Update Infrastructure 3 Client Configur 4.2 kB/s | 1.9 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 - AppStre 39 MB/s | 30 MB 00:00
Red Hat Enterprise Linux 8 for x86_64 - BaseOS 46 MB/s | 33 MB 00:00
Red Hat Enterprise Linux 8 for x86_64 - High Av 6.3 MB/s | 2.3 MB 00:00
Repo-id : docker-ce-stable
Repo-name : Docker CE Stable - x86_64
Repo-revision : 1622662057
Repo-updated : Wed 02 Jun 2021 07:27:37 PM UTC
Repo-pkgs : 38
Repo-available-pkgs: 38
Repo-size : 937 M
Repo-baseurl : https://download.docker.com/linux/centos/8/x86_64/stable
Repo-expire : 172,800 second(s) (last: Fri 04 Jun 2021 03:11:31 AM UTC)
Repo-filename : /etc/yum.repos.d/docker-ce.repo
Repo-id : rhel-8-appstream-rhui-rpms
Repo-name : Red Hat Enterprise Linux 8 for x86_64 - AppStream from RHUI
: (RPMs)
Repo-revision : 1622767016
Repo-updated : Fri 04 Jun 2021 12:38:34 AM UTC
Repo-pkgs : 18,298
Repo-available-pkgs: 16,314
Repo-size : 44 G
Repo-mirrors : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/mirror/content/dist/rhel8/rhui/8/x86_64/appstream/os
Repo-baseurl : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/repos/content/dist/rhel8/rhui/8/x86_64/appstream/os
: (0 more)
Repo-expire : 172,800 second(s) (last: Fri 04 Jun 2021 03:11:32 AM UTC)
Repo-filename : /etc/yum.repos.d/redhat-rhui-ha.repo
Repo-id : rhel-8-baseos-rhui-rpms
Repo-name : Red Hat Enterprise Linux 8 for x86_64 - BaseOS from RHUI
: (RPMs)
Repo-revision : 1622745465
Repo-updated : Thu 03 Jun 2021 06:40:56 PM UTC
Repo-pkgs : 7,725
Repo-available-pkgs: 7,722
Repo-size : 11 G
Repo-mirrors : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/mirror/content/dist/rhel8/rhui/8/x86_64/baseos/os
Repo-baseurl : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/repos/content/dist/rhel8/rhui/8/x86_64/baseos/os
: (0 more)
Repo-expire : 172,800 second(s) (last: Fri 04 Jun 2021 03:11:40 AM UTC)
Repo-filename : /etc/yum.repos.d/redhat-rhui-ha.repo
Repo-id : rhui-client-config-server-8-ha
Repo-name : Red Hat Update Infrastructure 3 Client Configuration Server
: 8 HA
Repo-revision : 1616077193
Repo-updated : Thu 18 Mar 2021 02:19:53 PM UTC
Repo-pkgs : 2
Repo-available-pkgs: 2
Repo-size : 68 k
Repo-mirrors : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/mirror/protected/rhui-client-config/rhel/server/8/x86_64/ha
Repo-baseurl : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/repos/protected/rhui-client-config/rhel/server/8/x86_64/ha
: (0 more)
Repo-expire : 172,800 second(s) (last: Fri 04 Jun 2021 03:11:32 AM UTC)
Repo-filename : /etc/yum.repos.d/redhat-rhui-client-config-ha.repo
Repo-id : rhui-rhel-8-for-x86_64-highavailability-rhui-rpms
Repo-name : Red Hat Enterprise Linux 8 for x86_64 - High Availability
: (RPMs) from RHUI
Repo-revision : 1621381187
Repo-updated : Tue 18 May 2021 11:39:50 PM UTC
Repo-pkgs : 361
Repo-available-pkgs: 360
Repo-size : 481 M
Repo-mirrors : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/mirror/content/dist/rhel8/rhui/8/x86_64/highavailability/os
Repo-baseurl : https://rhui3.ap-northeast-1.aws.ce.redhat.com/pulp/repos/content/dist/rhel8/rhui/8/x86_64/highavailability/os
: (0 more)
Repo-expire : 172,800 second(s) (last: Fri 04 Jun 2021 03:11:47 AM UTC)
Repo-filename : /etc/yum.repos.d/redhat-rhui-ha.repo
Total packages: 26,424
dockerのインストール
[root@ip-10-0-1-4 ~]# dnf install docker-ce
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:00:44 ago on Fri 04 Jun 2021 03:11:47 AM UTC.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
docker-ce x86_64 3:20.10.7-3.el8 docker-ce-stable 27 M
Installing dependencies:
container-selinux noarch 2:2.158.0-1.module+el8.4.0+10607+f4da7515
rhel-8-appstream-rhui-rpms 51 k
containerd.io x86_64 1.4.6-3.1.el8 docker-ce-stable 34 M
docker-ce-cli x86_64 1:20.10.7-3.el8 docker-ce-stable 33 M
docker-ce-rootless-extras
x86_64 20.10.7-3.el8 docker-ce-stable 9.2 M
docker-scan-plugin x86_64 0.8.0-3.el8 docker-ce-stable 4.2 M
fuse-common x86_64 3.2.1-12.el8 rhel-8-baseos-rhui-rpms 21 k
fuse-overlayfs x86_64 1.4.0-2.module+el8.4.0+10607+f4da7515
rhel-8-appstream-rhui-rpms 72 k
fuse3 x86_64 3.2.1-12.el8 rhel-8-baseos-rhui-rpms 50 k
fuse3-libs x86_64 3.2.1-12.el8 rhel-8-baseos-rhui-rpms 94 k
iptables x86_64 1.8.4-17.el8 rhel-8-baseos-rhui-rpms 586 k
libcgroup x86_64 0.41-19.el8 rhel-8-baseos-rhui-rpms 70 k
libnetfilter_conntrack x86_64 1.0.6-5.el8 rhel-8-baseos-rhui-rpms 65 k
libnfnetlink x86_64 1.0.1-13.el8 rhel-8-baseos-rhui-rpms 33 k
libnftnl x86_64 1.1.5-4.el8 rhel-8-baseos-rhui-rpms 83 k
libslirp x86_64 4.3.1-1.module+el8.4.0+10607+f4da7515
rhel-8-appstream-rhui-rpms 69 k
policycoreutils-python-utils
noarch 2.9-14.el8 rhel-8-baseos-rhui-rpms 252 k
slirp4netns x86_64 1.1.8-1.module+el8.4.0+10607+f4da7515
rhel-8-appstream-rhui-rpms 51 k
Enabling module streams:
container-tools rhel8
Transaction Summary
================================================================================
Install 18 Packages
Total download size: 108 M
Installed size: 441 M
Is this ok [y/N]: y
Downloading Packages:
(1/18): docker-ce-20.10.7-3.el8.x86_64.rpm 55 MB/s | 27 MB 00:00
(2/18): docker-ce-rootless-extras-20.10.7-3.el8 55 MB/s | 9.2 MB 00:00
(3/18): docker-scan-plugin-0.8.0-3.el8.x86_64.r 27 MB/s | 4.2 MB 00:00
(4/18): container-selinux-2.158.0-1.module+el8. 644 kB/s | 51 kB 00:00
(5/18): libslirp-4.3.1-1.module+el8.4.0+10607+f 799 kB/s | 69 kB 00:00
(6/18): slirp4netns-1.1.8-1.module+el8.4.0+1060 692 kB/s | 51 kB 00:00
(7/18): fuse-overlayfs-1.4.0-2.module+el8.4.0+1 979 kB/s | 72 kB 00:00
(8/18): libcgroup-0.41-19.el8.x86_64.rpm 930 kB/s | 70 kB 00:00
(9/18): fuse-common-3.2.1-12.el8.x86_64.rpm 295 kB/s | 21 kB 00:00
(10/18): libnetfilter_conntrack-1.0.6-5.el8.x86 766 kB/s | 65 kB 00:00
(11/18): fuse3-3.2.1-12.el8.x86_64.rpm 708 kB/s | 50 kB 00:00
(12/18): libnfnetlink-1.0.1-13.el8.x86_64.rpm 457 kB/s | 33 kB 00:00
(13/18): fuse3-libs-3.2.1-12.el8.x86_64.rpm 1.2 MB/s | 94 kB 00:00
(14/18): docker-ce-cli-20.10.7-3.el8.x86_64.rpm 19 MB/s | 33 MB 00:01
(15/18): libnftnl-1.1.5-4.el8.x86_64.rpm 414 kB/s | 83 kB 00:00
(16/18): policycoreutils-python-utils-2.9-14.el 2.8 MB/s | 252 kB 00:00
(17/18): containerd.io-1.4.6-3.1.el8.x86_64.rpm 17 MB/s | 34 MB 00:01
(18/18): iptables-1.8.4-17.el8.x86_64.rpm 2.6 MB/s | 586 kB 00:00
--------------------------------------------------------------------------------
Total 51 MB/s | 108 MB 00:02
warning: /var/cache/dnf/docker-ce-stable-fa9dc42ab4cec2f4/packages/containerd.io-1.4.6-3.1.el8.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Docker CE Stable - x86_64 37 kB/s | 1.6 kB 00:00
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <docker@docker.com>"
Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
From : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : docker-scan-plugin-0.8.0-3.el8.x86_64 1/18
Running scriptlet: docker-scan-plugin-0.8.0-3.el8.x86_64 1/18
Installing : docker-ce-cli-1:20.10.7-3.el8.x86_64 2/18
Running scriptlet: docker-ce-cli-1:20.10.7-3.el8.x86_64 2/18
Installing : libnfnetlink-1.0.1-13.el8.x86_64 3/18
Running scriptlet: libnfnetlink-1.0.1-13.el8.x86_64 3/18
Installing : libnetfilter_conntrack-1.0.6-5.el8.x86_64 4/18
Running scriptlet: libnetfilter_conntrack-1.0.6-5.el8.x86_64 4/18
Installing : policycoreutils-python-utils-2.9-14.el8.noarch 5/18
Running scriptlet: container-selinux-2:2.158.0-1.module+el8.4.0+10607 6/18
Installing : container-selinux-2:2.158.0-1.module+el8.4.0+10607 6/18
Running scriptlet: container-selinux-2:2.158.0-1.module+el8.4.0+10607 6/18
Installing : containerd.io-1.4.6-3.1.el8.x86_64 7/18
Running scriptlet: containerd.io-1.4.6-3.1.el8.x86_64 7/18
Installing : libnftnl-1.1.5-4.el8.x86_64 8/18
Running scriptlet: libnftnl-1.1.5-4.el8.x86_64 8/18
Running scriptlet: iptables-1.8.4-17.el8.x86_64 9/18
Installing : iptables-1.8.4-17.el8.x86_64 9/18
Running scriptlet: iptables-1.8.4-17.el8.x86_64 9/18
Installing : fuse3-libs-3.2.1-12.el8.x86_64 10/18
Running scriptlet: fuse3-libs-3.2.1-12.el8.x86_64 10/18
Installing : fuse-common-3.2.1-12.el8.x86_64 11/18
Installing : fuse3-3.2.1-12.el8.x86_64 12/18
Installing : fuse-overlayfs-1.4.0-2.module+el8.4.0+10607+f4da75 13/18
Running scriptlet: fuse-overlayfs-1.4.0-2.module+el8.4.0+10607+f4da75 13/18
Running scriptlet: libcgroup-0.41-19.el8.x86_64 14/18
Installing : libcgroup-0.41-19.el8.x86_64 14/18
Running scriptlet: libcgroup-0.41-19.el8.x86_64 14/18
Installing : libslirp-4.3.1-1.module+el8.4.0+10607+f4da7515.x86 15/18
Installing : slirp4netns-1.1.8-1.module+el8.4.0+10607+f4da7515. 16/18
Installing : docker-ce-rootless-extras-20.10.7-3.el8.x86_64 17/18
Running scriptlet: docker-ce-rootless-extras-20.10.7-3.el8.x86_64 17/18
Installing : docker-ce-3:20.10.7-3.el8.x86_64 18/18
Running scriptlet: docker-ce-3:20.10.7-3.el8.x86_64 18/18
Running scriptlet: container-selinux-2:2.158.0-1.module+el8.4.0+10607 18/18
Running scriptlet: docker-ce-3:20.10.7-3.el8.x86_64 18/18
Verifying : containerd.io-1.4.6-3.1.el8.x86_64 1/18
Verifying : docker-ce-3:20.10.7-3.el8.x86_64 2/18
Verifying : docker-ce-cli-1:20.10.7-3.el8.x86_64 3/18
Verifying : docker-ce-rootless-extras-20.10.7-3.el8.x86_64 4/18
Verifying : docker-scan-plugin-0.8.0-3.el8.x86_64 5/18
Verifying : container-selinux-2:2.158.0-1.module+el8.4.0+10607 6/18
Verifying : libslirp-4.3.1-1.module+el8.4.0+10607+f4da7515.x86 7/18
Verifying : slirp4netns-1.1.8-1.module+el8.4.0+10607+f4da7515. 8/18
Verifying : fuse-overlayfs-1.4.0-2.module+el8.4.0+10607+f4da75 9/18
Verifying : libcgroup-0.41-19.el8.x86_64 10/18
Verifying : fuse-common-3.2.1-12.el8.x86_64 11/18
Verifying : libnetfilter_conntrack-1.0.6-5.el8.x86_64 12/18
Verifying : fuse3-3.2.1-12.el8.x86_64 13/18
Verifying : libnfnetlink-1.0.1-13.el8.x86_64 14/18
Verifying : fuse3-libs-3.2.1-12.el8.x86_64 15/18
Verifying : libnftnl-1.1.5-4.el8.x86_64 16/18
Verifying : policycoreutils-python-utils-2.9-14.el8.noarch 17/18
Verifying : iptables-1.8.4-17.el8.x86_64 18/18
Installed products updated.
Installed:
container-selinux-2:2.158.0-1.module+el8.4.0+10607+f4da7515.noarch
containerd.io-1.4.6-3.1.el8.x86_64
docker-ce-3:20.10.7-3.el8.x86_64
docker-ce-cli-1:20.10.7-3.el8.x86_64
docker-ce-rootless-extras-20.10.7-3.el8.x86_64
docker-scan-plugin-0.8.0-3.el8.x86_64
fuse-common-3.2.1-12.el8.x86_64
fuse-overlayfs-1.4.0-2.module+el8.4.0+10607+f4da7515.x86_64
fuse3-3.2.1-12.el8.x86_64
fuse3-libs-3.2.1-12.el8.x86_64
iptables-1.8.4-17.el8.x86_64
libcgroup-0.41-19.el8.x86_64
libnetfilter_conntrack-1.0.6-5.el8.x86_64
libnfnetlink-1.0.1-13.el8.x86_64
libnftnl-1.1.5-4.el8.x86_64
libslirp-4.3.1-1.module+el8.4.0+10607+f4da7515.x86_64
policycoreutils-python-utils-2.9-14.el8.noarch
slirp4netns-1.1.8-1.module+el8.4.0+10607+f4da7515.x86_64
Complete!
dockerのstartとenable
[root@ip-10-0-1-4 ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@ip-10-0-1-4 ~]# systemctl is-active docker
active
[root@ip-10-0-1-4 ~]# systemctl is-enabled docker
enabled
docker-composeのインストール
最後にdocker-compose --versionと入力してバージョンが出力されればOK
[root@ip-10-0-1-4 work]# curl -L "https://github.com/docker/compose/releases/download/1.25.0/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 24346 0 --:--:-- --:--:-- --:--:-- 24346
100 16.2M 100 16.2M 0 0 20.8M 0 --:--:-- --:--:-- --:--:-- 51.7M
[root@ip-10-0-1-4 work]# chmod 755 /usr/local/bin/docker-compose
[root@ip-10-0-1-4 work]# docker-compose --version
docker-compose version 1.25.0, build 0a186604
この記事が気に入ったらサポートをしてみませんか?