【Docker】containerd v2.1ではmediatypeのサポートが切れているDockerイメージを無理やり動かす

こんにちは

 

今回は古すぎるDockerイメージを無理やり containerd v2.1 で動かしてみた話です。

(今後の人生で一生使うことはないと思います、、、)

 

具体的には、Skopeo を利用して、Docker デーモンを介さずに古い形式を読み込み、新しい形式(V2 や OCI)に変換してローカルに保存するようにしました。

 

■Skopeoについて

読み方は「スケーポー」らしく、あまりに本人には馴染みがないです

コンテナイメージの検査、コピー、署名、転送をDockerデーモンなしで実施可能なので、Dockerデーモンを介した場合に発生するエラーを回避可能になる

ちなみに下記が –help の結果です

# skopeo --help
Various operations with container images and container image registries

Usage:
  skopeo [flags]
  skopeo [command]

Available Commands:
  copy                                          Copy an IMAGE-NAME from one location to another
  delete                                        Delete image IMAGE-NAME
  generate-sigstore-key                         Generate a sigstore public/private key pair
  help                                          Help about any command
  inspect                                       Inspect image IMAGE-NAME
  list-tags                                     List tags in the transport/repository specified by the SOURCE-IMAGE
  login                                         Login to a container registry
  logout                                        Logout of a container registry
  manifest-digest                               Compute a manifest digest of a file
  standalone-sign                               Create a signature using local files
  standalone-verify                             Verify a signature using local files
  sync                                          Synchronize one or more images from one location to another

Flags:
      --command-timeout duration   timeout for the command execution
      --debug                      enable debug output
  -h, --help                       help for skopeo
      --insecure-policy            run the tool without any policy check
      --override-arch ARCH         use ARCH instead of the architecture of the machine for choosing images
      --override-os OS             use OS instead of the running OS for choosing images
      --override-variant VARIANT   use VARIANT instead of the running architecture variant for choosing images
      --policy string              Path to a trust policy file
      --registries.d DIR           use registry configuration files in DIR (e.g. for container signature storage)
      --tmpdir string              directory used to store temporary files
  -v, --version                    Version for Skopeo

Use "skopeo [command] --help" for more information about a command.

 

 

■環境

OS:AlmaLinux9 (Vagrant)

Dockerバージョン:29.2.1, build a5c7197

Dockerイメージ:httpd:2.4.16 (10年前のイメージですね)

 

■手順

※事前にAlmaLinux9の仮想マシン作成とDockerのインストールは済ませておいてください

参考:【Docker】docker-composeを利用してVM上に独自ドメインでWebサイトを公開する

 

1. イメージのプル

docker pull httpd:2.4.16

→ 下記サポート外のエラーが出ることを確認する

Error response from daemon: not implemented: media type "application/vnd.docker.distribution.manifest.v1+prettyjws" is no longer supported since containerd v2.1, please rebuild the image as "application/vnd.docker.distribution.manifest.v2+json" or "application/vnd.oci.image.manifest.v1+json"

 

2. Skopeoのインストール

dnf install skopeo -y

→ Complete! が出ればOKです

 

3. コンバートの実施

skopeo copy --format v2s2 docker://httpd:2.4.16 docker-daemon:httpd:2.4.16

→ –format v2s2 でフォーマットを指定して、ローカルのDockerデーモンへ直接コピーしています

 

下記のように出力され始めたらOKです

Getting image source signatures
Copying blob f8efbffe7b95 ...                                      7.2 MiB/s
Copying blob f8efbffe7b95 done
Copying blob a3ed95caeb02 done
Copying blob a3ed95caeb02 skipped: already exists
Copying blob a3ed95caeb02 skipped: already exists
Copying blob fffb6eca3dac done
Copying blob a3ed95caeb02 skipped: already exists
Copying blob 5b3039cd40c9 done
Copying blob 94118c67a40b done
Copying blob a3ed95caeb02 skipped: already exists
Copying blob a3ed95caeb02 skipped: already exists
Copying blob f3509cb04d70 done
Copying blob a7ff98debbdc done
Copying blob a3ed95caeb02 skipped: already exists
Copying blob a3ed95caeb02 skipped: already exists
Copying config 2943168f35 done   |
Writing manifest to image destination

 

4. イメージの確認

docker images

→ 下記のように表示されればOKです

                                                                                                                                                             
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
httpd:2.4.16   c02df0945e1f        244MB         61.9MB

 

5. ポートを指定してコンテナの起動

docker run --name test-container -d -p 8080:80 httpd:2.4.16

 

docker container ps -a

→ 下記のように起動すればOKです

CONTAINER ID   IMAGE          COMMAND              CREATED         STATUS         PORTS                                     NAMES
b97b9c37345d   httpd:2.4.16   "httpd-foreground"   9 seconds ago   Up 7 seconds   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp   test-container

 

6. コンテナ内でバージョンの確認

docker exec -it {コンテナID} bash

 

httpd -v

→ 下記のように 2.4.16 になっていればOK

Server version: Apache/2.4.16 (Unix)
Server built:   Sep  9 2015 21:45:31

 

■まとめ

いかがでしたでしょうか?

いつも通りあまり使うことはないかもしれませんが、もし古い media type のイメージを使う場合は割と使えそうな方法かなと思いました

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA