Red Hat Training

A Red Hat training course is available for RHEL 8

18.5. コンテナーでの Buildah の実行

この手順では、コンテナーで Buildah を実行し、イメージを基に作業コンテナーを作成する方法を説明します。

前提条件

  • container-tools モジュールがインストールされている。

手順

  1. registry.redhat.io レジストリーにログインします。

    $ podman login registry.redhat.io
    Username: myuser@mycompany.com
    Password: <password>
    Login Succeeded!
  2. registry.redhat.io/rhel8/buildah イメージをプルして実行します。

    # podman run --rm --device /dev/fuse -it \
      registry.redhat.io/rhel8/buildah /bin/bash
    • --rm オプションは、コンテナーの終了後に registry.redhat.io/rhel8/buildah イメージを削除します。
    • --device オプションは、ホストデバイスをコンテナーに追加します。
    • sys_chroot - 別のルートディレクトリーに変更する機能。コンテナーのデフォルト機能には含まれていません。
  3. registry.access.redhat.com/ubi8 イメージを使用して、新しいコンテナーを作成します。

    # buildah from registry.access.redhat.com/ubi8
    ...
    ubi8-working-container
  4. ubi8-working-container コンテナー内で ls / コマンドを実行します。

    # buildah run --isolation=chroot ubi8-working-container ls /
    bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv
  5. 必要に応じて、ローカルストレージ内の全イメージをリスト表示します。

    # buildah images
    REPOSITORY                        TAG      IMAGE ID       CREATED       SIZE
    registry.access.redhat.com/ubi8   latest   ecbc6f53bba0   5 weeks ago   211 MB
  6. 必要に応じて、作業用コンテナーとそのベースイメージをリスト表示します。

    # buildah containers
    CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
    0aaba7192762     *     ecbc6f53bba0 registry.access.redhat.com/ub... ubi8-working-container
  7. 必要に応じて、registry.access.redhat.com/ubi8 イメージを registry.example.com にあるローカルレジストリーにプッシュします。

    # buildah push ecbc6f53bba0 registry.example.com:5000/ubi8/ubi