zaki work log

作業ログやら生活ログやらなんやら

[Oracle Cloud] 無料枠のA1.FlexのコンピュートインスタンスにDockerインストール (Ubuntu/Oracle Linux)

少し前に比べると、最大で4CPUs・RAM24GBまで無料で使用できるA1.Flexのコンピュートインスタンス(VM)を作成しやすくなったのでお試し。
結論から言うとVMのイメージはUbuntuであれば問題なし。
Oracle Linuxの場合はデフォルトの7.9より8の方が手間は無い。ただし、Docker公式はOracle Linux用のパッケージは用意されてないのでここで紹介してる手順は一応動くよというレベルで当然無保証。

あとアーキテクチャは普段よく使用されているamd64でなくarm64になるので、使いたいイメージによっては公開されてないこともあるので注意。(Docker Hubのイメージ検索の「OS/ARCH」のところにlinux/arm/v*のあるイメージであればデプロイ可能)

Ubuntu

特に問題無し。公式の手順通りでインストールできる。

docs.docker.com

$ uname -a
Linux opc-ubu-a1 5.11.0-1016-oracle #17~20.04.1-Ubuntu SMP Thu Aug 12 06:20:07 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
$ sudo apt-get update
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

stableリポジトリの追加は、arm64用の設定を行う。

$ echo \
  "deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

インストール

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:55:05 2021
 OS/Arch:           linux/arm64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:53:13 2021
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

実行

$ sudo docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
109db8fad215: Pull complete 
Digest: sha256:61bd3cb6014296e214ff4c6407a5a7e7092dfa8eefdbbec539e133e97f63e09f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Oracle Linux

Oracle Linux用のパッケージは用意されてないので、お互いRHEL互換ということでCentOS用の手順でお試し(したら動いた、というもの)。
インストールおよびざっくり動かした感じではこれで大丈夫そう。(無保証)

docs.docker.com

以前(1.13?)はOracle Linux用(ver 6, 7)のインストール手順もあったっぽいけど、現在(2021.09時点)は無いみたい。

ver 8

Oracle Linux 8の場合はCentOS用の手順そのままでOK.

$ uname -a
Linux opc-ol8-a1 5.4.17-2102.204.4.4.el8uek.aarch64 #2 SMP Tue Aug 17 20:32:12 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux
$ cat /etc/oracle-release 
Oracle Linux Server release 8.4
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum install docker-ce docker-ce-cli containerd.io

Ubuntuと異なり、インストールしただけだとサービスは有効にならないので有効化する。

$ systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com
$ sudo systemctl enable --now docker
$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:54:06 2021
 OS/Arch:           linux/arm64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:52:39 2021
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

実行

$ sudo docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
109db8fad215: Pull complete 
Digest: sha256:61bd3cb6014296e214ff4c6407a5a7e7092dfa8eefdbbec539e133e97f63e09f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

ver 7.9

7.9(OCIでコンピュートインスタンス作るときはこれがデフォルトになってる)の場合は、これもCentOS用の手順通りでインストールできるけど、Dockerが依存するパッケージのインストールがデフォルトだとリポジトリが無効になってて失敗するので、これを追加するための1手順が必要。

$ uname -a
Linux opc-ol7-a1 5.4.17-2102.204.4.4.el7uek.aarch64 #2 SMP Wed Aug 18 11:37:16 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux
$ cat /etc/oracle-release 
Oracle Linux Server release 7.9
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum install docker-ce docker-ce-cli containerd.io

[...]

エラー: パッケージ: docker-ce-rootless-extras-20.10.8-3.el7.aarch64 (docker-ce-stable)
             要求: fuse-overlayfs >= 0.7
エラー: パッケージ: docker-ce-rootless-extras-20.10.8-3.el7.aarch64 (docker-ce-stable)
             要求: slirp4netns >= 0.4
 問題を回避するために --skip-broken を用いることができます。
 これらを試行できます: rpm -Va --nofiles --nodigest

VM作成直後の状態だと、fuse-overlayfsslirp4netnsについて依存関係を解決できずこのようにエラーになる。

yum.oracle.com

この2つのパッケージは、ol7_developer リポジトリに含まれるので、リポジトリを有効にすればOK.

$ sudo yum-config-manager --enable ol7_developer

これでsudo yum install docker-ce docker-ce-cli containerd.ioでインストールできるようになる。

[...]

インストール:
  containerd.io.aarch64 0:1.4.9-3.1.el7             docker-ce.aarch64 3:20.10.8-3.el7             docker-ce-cli.aarch64 1:20.10.8-3.el7            

依存性関連をインストールしました:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8   docker-ce-rootless-extras.aarch64 0:20.10.8-3.el7   fuse-overlayfs.aarch64 0:0.7.2-6.el7_8  
  fuse3-libs.aarch64 0:3.6.1-4.el7                     slirp4netns.aarch64 0:0.4.3-4.el7_8                

完了しました!

あとはver8の場合と同じ。

$ sudo systemctl enable --now docker
$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:55:48 2021
 OS/Arch:           linux/arm64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:54:18 2021
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

実行

$ sudo docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
109db8fad215: Pull complete 
Digest: sha256:61bd3cb6014296e214ff4c6407a5a7e7092dfa8eefdbbec539e133e97f63e09f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

ほかにも、デフォルトのリポジトリだとGitのクライアントバージョンも1系なので、今ならもうOracle Linux使うなら7.9より8の方が良いのかな?


CPUアーキテクチャとかあまりちゃんと理解できてないので間違ったこと書いてたらすみません。