1
1

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 1 year has passed since last update.

Podmanを使ってAWS ECRにイメージプッシュ

Last updated at Posted at 2022-03-15

はじめに

これからはPodmanを使ってかなきゃと勝手に思って、podmanコマンドでECRにコンテナイメージをプッシュしてみました。
結果、dockerコマンド使う際と同じでした。

環境

Windows 11 WSL2 Ubuntu 20.04
Podman 3.4.2

いざプッシュ

こちらのガイドに従い、イメージをプッシュしてみる。dockerpodmanに読み替えるだけです。

まずはログイン。
(MFA使った環境なのでmfa用のプロファイル使っています)

$ aws ecr get-login-password --profile mfa-profile | podman login --username AWS --password-stdin xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com
Login Succeeded!

レポジトリ作成&確認

$ aws ecr create-repository --repository-name hogehoge --image-scanning-configuration scanOnPush=true --profile mfa-profile
{
    "repository": {
        "repositoryArn": "arn:aws:ecr:us-east-1:xxxxxxxxxxx:repository/hogehoge",
        "registryId": "xxxxxxxxxxx",
        "repositoryName": "hogehoge",
        "repositoryUri": "xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge",
        "createdAt": "2022-03-15T22:27:39+09:00",
        "imageTagMutability": "MUTABLE",
        "imageScanningConfiguration": {
            "scanOnPush": true
        },
        "encryptionConfiguration": {
            "encryptionType": "AES256"
        }
    }
}
$
$ aws ecr describe-repositories --profile mfa-profile  ←作成確認
{
    "repositories": [
        {
            "repositoryArn": "arn:aws:ecr:us-east-1:xxxxxxxxxxx:repository/hogehoge",
            "registryId": "xxxxxxxxxxx",
            "repositoryName": "hogehoge",
            "repositoryUri": "xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge",
            "createdAt": "2022-03-15T22:27:39+09:00",
            "imageTagMutability": "MUTABLE",
            "imageScanningConfiguration": {
                "scanOnPush": true
            },
            "encryptionConfiguration": {
                "encryptionType": "AES256"
            }
        }
    ]
}

イメージのタグ付け

$ podman images
REPOSITORY                                                                                  TAG         IMAGE ID      CREATED     SIZE
docker.io/library/busybox                                                                   latest      2fb6fc2d97e1  3 days ago  1.46 MB
$ 
$ podman tag docker.io/library/busybox:latest xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge:latest
$ podman images
REPOSITORY                                                                                  TAG         IMAGE ID      CREATED     SIZE
docker.io/library/busybox                                                                   latest      2fb6fc2d97e1  3 days ago  1.46 MB
xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge                                       latest      2fb6fc2d97e1  3 days ago  1.46 MB

イメージのプッシュ

$ podman push xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge:latest
Getting image source signatures
Copying blob 797ac4999b67 done
Copying config 2fb6fc2d97 done
Writing manifest to image destination
Storing signatures

確認

$ aws ecr list-images --repository-name hogehoge --profile mfa-profile
{
    "imageIds": [
        {
            "imageDigest": "sha256:f863e9899e06d22fd5b8cbbded37523efd2c0246a1c82a1f08e2939034de6a8f",
            "imageTag": "latest"
        }
    ]
}

ここまでできれば満足だが、せっかくなのドキュメントどおり一通り最後までやってみる。

イメージのプル

$ podman pull xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge:latest
Trying to pull xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge:latest...
Getting image source signatures
Copying blob 878eff9e7898 skipped: already exists
Copying config 2fb6fc2d97 done
Writing manifest to image destination
Storing signatures
2fb6fc2d97e10c79983aa10e013824cc7fc8bae50630e32159821197dda95fe3

イメージ削除&レポジトリ削除

$ aws ecr batch-delete-image --repository-name hogehoge --image-ids imageTag=latest --profile mfa-profile ←イメージ削除
{
    "imageIds": [
        {
            "imageDigest": "sha256:f863e9899e06d22fd5b8cbbded37523efd2c0246a1c82a1f08e2939034de6a8f",
            "imageTag": "latest"
        }
    ],
    "failures": []
}
$ aws ecr list-images --repository-name hogehoge --profile mfa-profile ←削除確認
{
    "imageIds": []
}
$ aws ecr delete-repository --repository-name hogehoge --force --profile mfa-profile ←レポジトリ削除
{
    "repository": {
        "repositoryArn": "arn:aws:ecr:us-east-1:xxxxxxxxxxxx:repository/hogehoge",
        "registryId": "xxxxxxxxxxxx",
        "repositoryName": "hogehoge",
        "repositoryUri": "xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/hogehoge",
        "createdAt": "2022-03-15T22:27:39+09:00",
        "imageTagMutability": "MUTABLE"
    }
}

Dockerのライセンス改定がありましたので、これからはPodmanも使えるようにならなきゃ。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?