見出し画像

【Windows】Podman Desktop を使ってみた

システムアイに出向中の松野です。Docker Desktopに代わるツールとして注目されている「Podman Desktop」というツールがあります。少し前にこれをWindowsにインストールして、コンテナ起動など基本操作を試してみましたので、今回はその様子を書いてみたいと思います。

Podman Desktopのインストール

公式サイトからダウンロードできます。
WSLのインストールも必要ですが、インストールされていなければ途中でダイアログが出て、WSLのリンクを教えてくれます。

インストールが完了したら、Podman Desktopを起動してみましょう。すると、下のようなウィンドウが立ち上がります。

また、コマンドプロンプトから podman コマンドが使えるようになっているので、確認します。

C:\Users\systemi>podman --help
Manage pods, containers and images

Usage:
  podman [options] [command]

Available Commands:
  attach      Attach to a running container
  build       Build an image using instructions from Containerfiles
  commit      Create new image based on the changed container
  container   Manage containers
  cp          Copy files/folders between a container and the local filesystem
  create      Create but do not start a container
  diff        Display the changes to the object's file system
  events      Show podman events
  exec        Run a process in a running container
  export      Export container's filesystem contents as a tar archive
  generate    Generate structured data based on containers, pods or volumes
  healthcheck Manage health checks on containers
  help        Help about any command
  history     Show history of a specified image
  image       Manage images
  images      List images in local storage
  import      Import a tarball to create a filesystem image
  info        Display podman system information
  init        Initialize one or more containers
  inspect     Display the configuration of object denoted by ID
  kill        Kill one or more running containers with a specific signal
  kube        Play containers, pods or volumes from a structured file
  load        Load image(s) from a tar archive
  login       Login to a container registry
  logout      Logout of a container registry
  logs        Fetch the logs of one or more containers
  machine     Manage a virtual machine
  manifest    Manipulate manifest lists and image indexes
  network     Manage networks
  pause       Pause all the processes in one or more containers
  pod         Manage pods
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image from a registry
  push        Push an image to a specified destination
  rename      Rename an existing container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Removes one or more images from local storage
  run         Run a command in a new container
  save        Save image(s) to an archive
  search      Search registry for image
  secret      Manage secrets
  start       Start one or more containers
  stats       Display a live stream of container resource usage statistics
  stop        Stop one or more containers
  system      Manage podman
  tag         Add an additional name to a local image
  top         Display the running processes of a container
  unpause     Unpause the processes in one or more containers
  untag       Remove a name from a local image
  update      update an existing container
  version     Display the Podman version information
  volume      Manage volumes
  wait        Block on one or more containers

Options:
  -c, --connection string         Connection to use for remote Podman service (default "podman-machine-default")
      --help                      Help for podman
      --identity string           path to SSH identity file, (CONTAINER_SSHKEY) (default "C:\\Users\\systemi\\.ssh\\podman-machine-default")
      --log-level string          Log messages above specified level (trace, debug, info, warn, warning, error, fatal, panic) (default "warn")
      --noout                     do not output to stdout
      --ssh string                define the ssh mode (default "golang")
      --storage-opt stringArray   Used to pass an option to the storage driver
      --url string                URL to access Podman service (CONTAINER_HOST) (default "ssh://user@localhost:50664/run/user/1000/podman/podman.sock")
  -v, --version                   version for podman

問題なく動作しているようですね。

Podman Desktopをインストールすると、WSLにPodmanのマシンが追加されるので、これをデフォルトに切り替えておきましょう。

C:\Users\systemi>wsl --list
Linux 用 Windows サブシステム ディストリビューション:
Ubuntu (既定)
podman-machine-default

C:\Users\systemi>wsl --set-default podman-machine-default

C:\Users\systemi>wsl --list
Linux 用 Windows サブシステム ディストリビューション:
podman-machine-default (既定)
Ubuntu

C:\Users\systemi>

切り替えたらWSL(で、デフォルトに設定した podman-machine-default)を起動して、同様にPodmanコマンドが使えることを確認します。

ちなみに、この podman-machine-default という名でインストールされたOSは実際には「Fedora」なので、パッケージのインストールする際は yum や dnf を使うことになりそうです。

You will be automatically entered into a nested process namespace where
systemd is running. If you need to access the parent namespace, hit ctrl-d
or type exit. This also means to log out you need to exit twice.

[user@PC853 ~]$ podman pull busybox
Resolved "busybox" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/busybox:latest...
Getting image source signatures
Copying blob 405fecb6a2fa done
Copying config 9d5226e6ce done
Writing manifest to image destination
Storing signatures
9d5226e6ce3fb6aee2822206a5ef85f38c303d2b37bfc894b419fca2c0501269
[user@PC853 ~]$ podman images
REPOSITORY                 TAG         IMAGE ID      CREATED      SIZE
docker.io/library/busybox  latest      9d5226e6ce3f  2 weeks ago  1.46 MB
[user@PC853 ~]$ podman run -it busybox echo "busybox!"
busybox!
[user@PC853 ~]$ podman ps -a
CONTAINER ID  IMAGE                             COMMAND        CREATED        STATUS                    PORTS       NAMES
fc61cd254efb  docker.io/library/busybox:latest  echo busybox!  7 seconds ago  Exited (0) 7 seconds ago              practical_cerf
[user@PC853 ~]$ podman rm fc61cd254efb
fc61cd254efb

# OSの確認
[user@PC853 ~]$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="36 (Container Image)"
ID=fedora
VERSION_ID=36
VERSION_CODENAME=""
PLATFORM_ID="platform:f36"
PRETTY_NAME="Fedora Linux 36 (Container Image)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:36"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f36/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=36
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=36
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Container Image"
VARIANT_ID=container
[user@PC853 ~]$

podman-compose

podman-compose も試してみます。

デフォルトではインストールされていませんので、dnfコマンドを使ってインストールします。

[user@PC853 ~]$ sudo dnf install podman-compose
Waiting for process with pid 234 to finish.
Fedora 36 - x86_64 - Updates                                                            3.6 kB/s | 4.1 kB     00:01
Fedora 36 - x86_64 - Updates                                                             36 kB/s | 5.1 MB     02:25
Fedora Modular 36 - x86_64 - Updates                                                    3.9 kB/s | 3.9 kB     00:00
Dependencies resolved.
========================================================================================================================
 Package                           Architecture          Version                           Repository              Size
========================================================================================================================
Installing:
 podman-compose                    noarch                1.0.3-6.fc36                      updates                 64 k
Installing dependencies:
 dbus-libs                         x86_64                1:1.14.4-1.fc36                   updates                155 k
 dnsmasq                           x86_64                2.86-10.fc36                      updates                339 k
 podman-plugins                    x86_64                4:4.3.1-1.fc36                    updates                1.2 M
 python3-click                     noarch                8.0.4-2.fc36                      fedora                 177 k
 python3-dotenv                    noarch                0.19.2-2.fc36                     fedora                  38 k
 python3-pyyaml                    x86_64                6.0-3.fc36                        fedora                 192 k
Installing weak dependencies:
 python3-dotenv+cli                noarch                0.19.2-2.fc36                     fedora                 9.9 k

Transaction Summary
========================================================================================================================
Install  8 Packages
...

Complete!
[user@PC853 ~]$ podman-compose --help
usage: podman-compose [-h] [-v] [-f file] [-p PROJECT_NAME] [--podman-path PODMAN_PATH] [--podman-args args]
                      [--podman-pull-args args] [--podman-push-args args] [--podman-build-args args]
                      [--podman-inspect-args args] [--podman-run-args args] [--podman-start-args args]
                      [--podman-stop-args args] [--podman-rm-args args] [--podman-volume-args args] [--no-ansi]
                      [--no-cleanup] [--dry-run]
                      {help,version,pull,push,build,up,down,ps,run,exec,start,stop,restart,logs} ...

options:
  -h, --help            show this help message and exit
  -v, --version         show version
  -f file, --file file  Specify an alternate compose file (default: docker-compose.yml)
  -p PROJECT_NAME, --project-name PROJECT_NAME
                        Specify an alternate project name (default: directory name)
  --podman-path PODMAN_PATH
                        Specify an alternate path to podman (default: use location in $PATH variable)
  --podman-args args    custom global arguments to be passed to `podman`
  --podman-pull-args args
                        custom arguments to be passed to `podman pull`
  --podman-push-args args
                        custom arguments to be passed to `podman push`
  --podman-build-args args
                        custom arguments to be passed to `podman build`
  --podman-inspect-args args
                        custom arguments to be passed to `podman inspect`
  --podman-run-args args
                        custom arguments to be passed to `podman run`
  --podman-start-args args
                        custom arguments to be passed to `podman start`
  --podman-stop-args args
                        custom arguments to be passed to `podman stop`
  --podman-rm-args args
                        custom arguments to be passed to `podman rm`
  --podman-volume-args args
                        custom arguments to be passed to `podman volume`
  --no-ansi             Do not print ANSI control characters
  --no-cleanup          Do not stop and remove existing pod & containers
  --dry-run             No action; perform a simulation of commands

command:
  {help,version,pull,push,build,up,down,ps,run,exec,start,stop,restart,logs}
    help                show help
    version             show version
    pull                pull stack images
    push                push stack images
    build               build stack images
    up                  Create and start the entire stack or some of its services
    down                tear down entire stack
    ps                  show status of containers
    run                 create a container similar to a service to run a one-off command
    exec                execute a command in a running container
    start               start specific services
    stop                stop specific services
    restart             restart specific services
    logs                show logs from services

ということで podman-compose のインストールが完了しました。試しにWordpressとMySQLのコンテナを起動してみます。yamlファイルはdocker-compose用のものをそのまま使ってみます。

[user@PC853 ~]$ vi compose.yml
[user@PC853 ~]$ cat compose.yml
version: '3'
services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_PASSWORD: my-secret-pw
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_NAME: wordpress_db
      WORDPRESS_DB_USER: user

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: my-secret-pw
      MYSQL_PASSWORD: my-secret-pw
      MYSQL_DATABASE: wordpress_db
      MYSQL_USER: user

[user@PC853 ~]$ podman-compose up -d
['podman', '--version', '']
using podman version: 4.3.0
** excluding:  set()
['podman', 'network', 'exists', 'user_default']
...
exit code: 0

"podman-compose up -d" を実行し、各コンテナが起動するのを待ち、http://localhost:8080 にアクセスすると、Wordpressの画面が表示されます。

docker-composeのyamlをそのまま利用できるようですね。

Podman DesktopのGUIの方にも、コンテナが表示されていました。

Roadmap

Podman Desktop のロードマップも公開されています。
Kubernetesレイヤの機能等が今後追加予定のようです。

まとめ

お手軽にPodmanの環境構築ができる Podman Desktop の紹介記事でした。
まだリリースされたばかりですが、コンテナは特に不自由なく実行できました。今後の機能実装にも期待したいですね!
――――――――――――――――――――――――――――――――――

執筆者プロフィール:松野 聖弘
前職はSESの会社でWebシステムの設計・構築に携わっており、Java、Python、Node.js等を用いたフルスタック開発やk8s環境へのリリース、CICDパイプライン構築を担当。
現在はその経験を活かして、k8s環境やCICDパイプラインの導入支援、コンサル業務に従事している。

【ご案内】
ITシステム開発やITインフラ運用の効率化、高速化、品質向上、その他、情シス部門の働き方改革など、IT自動化導入がもたらすメリットは様々ございます。

IT業務の自動化にご興味・ご関心ございましたら、まずは一度、IT自動化の専門家リアルグローブ・オートメーティッド(RGA)にご相談ください!

お問合せは以下の窓口までお願いいたします。

【お問い合わせ窓口】
窓口:rga@systemi.co.jp
URL:https://rg-automated.jp

みんなにも読んでほしいですか?

オススメした記事はフォロワーのタイムラインに表示されます!