📝

podman で postgresql サーバを動かす 前編

2025/02/10に公開

大遅刻でも dockerとその後継 にちゃんと向き合う。

  • 何時でも何処でもイジれるコンテナで いまさら docker 入門とは思うが便利なんだしつっぱらず使いましょう。

docker は有償ですか・・そうですか。

  • 動かしたいけど、ライセンスが・・・このことを考えたら、podman を選ぶのが楽そう。
    ちなみに、docker後継では・・
  • FreeBSD でも containerdとかつかえば linuxのコンテナ動きます(まだ遅いけど)
  • FreeBSD でも podman (実験的と言ってますが)はかろうじて動くのだそうで・・・多分遅いでしょう使えないでしょう。でも仕方ないです。

取り敢えずの目標は、expressjs のアプリが動くコンテナをこしらえる。

  • gihubでもなんでも、repoからぽいっとデプロイしたら動いてくれればとりあえずおk。
  • FreeBSDでも動いてくれないかなというのは、そのうち考えるとして。

さてさて podman 登場

何回も podmain と打ってしまう悪い指クセ・・・

$ >>> sudo apt install podman 
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了        
状態情報を読み取っています... 完了        
以下の追加パッケージがインストールされます:
  aardvark-dns buildah catatonit conmon containernetworking-plugins
  fuse-overlayfs golang-github-containers-common
  golang-github-containers-image netavark passt
提案パッケージ:
  containers-storage docker-compose
以下のパッケージが新たにインストールされます:
  aardvark-dns buildah catatonit conmon containernetworking-plugins
  fuse-overlayfs golang-github-containers-common
  golang-github-containers-image netavark passt podman
アップグレード: 0 個、新規インストール: 11 個、削除: 0 個、保留: 74 個。
31.9 MB のアーカイブを取得する必要があります。
この操作後に追加で 129 MB のディスク容量が消費されます。
続行しますか? [Y/n] Y 
  • docker はもう入れてあるんですが、ライセンスのこともあるし、 FreeBSD では podman の ports がやって来てるので、慣れておこうと思います。
$ podman 
Manage pods, containers and images

Usage:
  podman [options] [command]

Available Commands:
  attach      Attach to a running container
  auto-update Auto update containers according to their auto-update policy
  build       Build an image using instructions from Containerfiles
  commit      Create new image based on the changed container
  compose     Run compose workloads via an external provider such as docker-compose or podman-compose
  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 system events
  exec        Run a process in a running container
  export      Export container's filesystem contents as a tar archive
  farm        Farm out builds to remote machines
  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       Log in to a container registry
  logout      Log out 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
  mount       Mount a working container's root filesystem
  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         Remove 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
  unmount     Unmount working container's root filesystem
  unpause     Unpause the processes in one or more containers
  unshare     Run a command in a modified user namespace
  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:
      --cgroup-manager string       Cgroup manager to use ("cgroupfs"|"systemd") (default "systemd")
      --conmon string               Path of the conmon binary
  -c, --connection string           Connection to use for remote Podman service
      --events-backend string       Events backend to use ("file"|"journald"|"none") (default "journald")
      --help                        Help for podman
      --hooks-dir strings           Set the OCI hooks directory path (may be set multiple times) (default [/usr/share/containers/oci/hooks.d])
      --identity string             path to SSH identity file, (CONTAINER_SSHKEY)
      --imagestore string           Path to the 'image store', different from 'graph root', use this to split storing the image into a separate 'image store', see 'man containers-storage.conf' for details
      --log-level string            Log messages above specified level (trace, debug, info, warn, warning, error, fatal, panic) (default "warn")
      --module strings              Load the containers.conf(5) module
      --network-cmd-path string     Path to the command for configuring the network
      --network-config-dir string   Path of the configuration directory for networks
      --out string                  Send output (stdout) from podman to a file
  -r, --remote                      Access remote Podman service
      --root string                 Path to the graph root directory where images, containers, etc. are stored
      --runroot string              Path to the 'run directory' where all state information is stored
      --runtime string              Path to the OCI-compatible binary used to run containers. (default "runc")
      --runtime-flag stringArray    add global flags for the container runtime
      --ssh string                  define the ssh mode (default "golang")
      --storage-driver string       Select which storage driver is used to manage storage of images and containers
      --storage-opt stringArray     Used to pass an option to the storage driver
      --syslog                      Output logging information to syslog as well as the console (default false)
      --tmpdir string               Path to the tmp directory for libpod state content.
                                    
                                    Note: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'.
                                     (default "/run/user/501/libpod/tmp")
      --transient-store             Enable transient container storage
      --url string                  URL to access Podman service (CONTAINER_HOST) (default "unix:///run/user/501/podman/podman.sock")
  -v, --version                     version for podman
      --volumepath string           Path to the volume directory in which volume data is stored
Error: missing command 'podman COMMAND'

  • docker と同じような使い勝手だと思われます。取り敢えずコンテナイメージを拾って動かせるか試したいと思います。まず当てずっぽうですが・・
$ podman pull postgresql16-server
Error: short-name "postgresql16-server" did not resolve to an alias and no unqualified-search registries are defined in "/etc/containers/registries.conf"
  • posgresql の podman でのコンテナイメージ名、在処をそもそも知りません。 repoをイジれと書いてありますので編集。
$ sudo vim /etc/containers/registries.conf
unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"]

つか、それなりのパスを知っていれば編集も必要ないようでした・・・(で動くのか?)

$    podman pull docker.io/library/postgres:16
  podman: コマンドが見つかりません
hiko@ryzen5700-pc:~/workdir/plating-solution-dataentry$ podman pull docker.io/library/postgres:16
Trying to pull docker.io/library/postgres:16...
Getting image source signatures
Copying blob 3b6992cf2918 done   | 
Copying blob c29f5b76f736 done   | 
Copying blob 1b97e303d014 done   | 
Copying blob 5d09b270019a done   | 
Copying blob 9d735a0b570c done   | 
Copying blob ff1ae98c5afe done   | 
Copying blob 6af5b0a8381b done   | 
Copying blob f8a2f3f2bb57 done   | 
Copying blob 071d7e2b1414 done   | 
Copying blob 92ce9438a1c4 done   | 
Copying blob 97dd3da5d022 done   | 
Copying blob 820eeecfbadf done   | 
Copying blob 161b744b7149 done   | 
Copying blob 9f4ee33118cf done   | 
Copying config eee71f45c6 done   | 
Writing manifest to image destination
eee71f45c6dfebd5d85644a85eb955b1f27d84ea4edccf9e21f51761cbed3818

podman の動かし方がわかってないので・・・

  • podman machine なる VMがあってそれを使うというのを見かけた。
$ podman machine init
Downloading VM image: fedora-coreos-41.20250130.2.0-qemu.x86_64.qcow2.xz: done  
Extracting compressed file: podman-machine-default_fedora-coreos-41.20250130.2.0-qemu.x86_64.qcow2: done  
Image resized.
Machine init complete
To start your machine run:

	podman machine start

  • おそらく ”VM"というから、素の docker よりも OS依存が少ないのかな。調べる →
$ podman machine start
Starting machine "podman-machine-default"
Error: unable to start host networking: "could not find \"gvproxy\" in one of {[/usr/local/libexec/podman /usr/local/lib/podman /usr/libexec/podman /usr/lib/podman] {<nil>}}.  To resolve this error, set the helper_binaries_dir key in the `[engine]` section of containers.conf to the directory containing your helper binaries."

Hmmm...

podman version 4.9.3
  • ということで、まだ CNI/Netavark のどちらでも良いが、これからの構築ならば、netavark 推奨ですね ✍
  • 取り敢えず手を動かしてみるまえに読み込んで翻訳・要約を試みます。

podman/tutorials/basic_networking を読む。

"Podman のコンテナネットワークにおける指針の一つ: コンテナが root権限を付与された実行環境かそうでないか。

pod の ネットワークモード[1]

コンテナ mode ネットワークモード 特徴
root-less slirp4netns 経路設定不可
root-full netavark 経路設定できる

pod のファイアウォール

  • 通常はポートマッピングで仲介して、外からのパケットをコンテナ内部のプロセスに渡す[2]
  • podの 実行時に自動的にマッピングすることが出来る。
  • コンテナが外界と通信しないときはファイアウォールの確認をせよ[3]
  • ファイアウォールの再読込で、netavark iptables ルールが削除されて root-fullコンテナの通信機能が麻痺してしまうことがある [4]

基本的なネットワーク (pod)

コンテナ mode network/if 特徴
root-less slirp4netns/tunnel ユーザ権限で利用可
root-full bridge/NAT NATで接続
root-full bridge/macvlan プラグインでネットワークアクセスも可能

調べものしているだけで日が暮れる!

  • 曖昧な FreeBSDの知識と比べつつとなると、本当に時間がいくらあっても足りない。
  • L2/L3 に関する FreeBSD/IPFW *でなければならない*問題なんかもちょっと引っかかるものがあるし、この辺りは闇が深くなってうっかりすると嘘しか書けない気がしてきた!
脚注
  1. FreeBSDでは 通常のjailとVNET-jailに相当する 1 ↩︎

  2. これはFreeBSD/jail では pfを使うことが多いので見慣れている 2 ↩︎

  3. これも よく整備が行き届いていない FreeBSD/jail,bastillebsdなどで適当に/etc/pf.confを放置した場合に相当する 3 ↩︎

  4. FreeBSD/VNET-Jailでは、ブリッジした仮想NICを設定し、コンテナ個別にFWを設定可能なほどに独立しているので、独立性が高いとも言えるが、L3ネットワーク制御から逸脱するともいえる。 4 ↩︎

Discussion