1. Docker hubからAmazon Linux 2をpullする
$ sudo docker pull amazonlinux:2
$ sudo docker images
2. コンテナにログイン
$ sudo docker run -i -t 484 /bin/bash
bash-4.2# cat /etc/system-release
Amazon Linux release 2 (Karoo)
### git install
$ yum update
$ yum -y install gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf
$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.19.2.tar.gz
bash: wget: command not found
あら?
$ yum install wget
$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.19.2.tar.gz
$ tar xzvf git-2.19.2.tar.gz
bash: tar: command not found
ありゃ
$ yum install tar
$ tar xzvf git-2.19.2.tar.gz
$ rm -rf git-2.19.2.tar.gz
$ cd git-2.19.2
$ make prefix=/usr/local all
bash: make: command not found
なにーーーーーーーーーーーーーーーー
$ yum install make
$ make prefix=/usr/local all
$ make prefix=/usr/local install
$ git –version
### Node.js install
// 省略
### httpd install
$ yum install httpd
$ systemctl start httpd
Failed to get D-Bus connection: Operation not permitted
原因
・—privilegedを使用 ・/sbin/initで起動 ・上記に合わせ、-itではなく-dで起動し、起動後にexec
$ sudo docker run -d –privileged –name amzn2 amazonlinux:2 /sbin/init
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused “exec: \”/sbin/init\”: stat /sbin/init: no such file or directory”: unknown.
amazonlinux2には/sbin/initがないとのこと
$ sudo docker exec -it amzn2 /bin/bash
$ yum install systemd-sysv
$ exit
$ sudo docker commit c922 amzn:2
$ docker run -d –privileged –name amzn amzn:2 /sbin/init
$ sudo docker exec -it amzn /bin/bash
$ systemctl start httpd
$ systemctl enable httpd
### PHP 7.3
### Ansible
// 省略
### docker commit & push
$ sudo docker commit ${containerId} {DockerName}/amzn
$ sudo docker login
$ sudo docker push ddddocker/amzn
The push refers to repository [docker.io/ddddocker/amzn]
7a035032cdab: Pushing 53.97MB/2.934GB
4948e9de7aa2: Pushing 46.8MB/1.031GB
あれ、3GB? こりゃあかんわ。
$ sudo docker history ddddocker/amzn
IMAGE CREATED CREATED BY SIZE COMMENT
1530f5eb21ed 8 minutes ago /sbin/init 2.93GB
558083a921e9 3 hours ago /bin/bash 1.03GB
484b3aa1f601 3 weeks ago /bin/sh -c #(nop) CMD [“/bin/bash”] 0B
こりゃあかん。こんなにdisk sizeが増えるとは思わなかった。
installしたimageをrepoから取得するのではなく、docker-composeでamazonlinux2をpullして、それからinstallするフローに変えた方が良さそうですね。