--- tags: note, podman, docker, container --- # Ubuntu podman-remote and windows podman [從來源自己建置](##Podman-build-from-source) 前提是已經用 windows 版的 podman 建立好 podman 了 目的是要在其他 wsl 連到已經建立好的 podman, 好實現共用不要重複建立 podman 的目的 而 client 端可以選 docker 或是 podman 或 podman-remote 以下就分兩個分別簡單講如何使用 ## Docker client ==沒有實驗確定可以使用== Docker 的解法比較簡單, 直接設定好 `DOCKER_HOST` 即可 因為 podman 有兼容 docker api, 所以直接同 docker 的用法 ```bash= # Example format DOCKER_HOST=/path/to/your/podman # Example-1 DOCKER_HOST=/mnt/wsl/podman.sock ``` 至於 Podman socket 的設定請參閱[^Podman-socket] [^Podman-socket]: [Automatically bind podman sockets for access by other WSL distributions #16660](https://github.com/containers/podman/issues/16660) ## Podman client Podman 本來設計就是 client-server, 所以可以直接用內建指令去連接到遠端的 Podman ### 最直接的方法(For Windows) 由於 windows 底下的 client 就是遠端到 wsl 底下, 所以直接照抄 windows podman client 就好 步驟: 1. 在 windwos 底下使用 `podman system connection list` 指令確認 podman client 的 URI 與 identity 2. 照抄到 ubuntu 那邊(請注意 identity 的 path 需要轉換成 /mnt/...) 3. End 範例: ```bash= podman system connection list # 得到的資訊 > Name URI Identity Default > podman-machine-default ssh://user@localhost:52156/run/user/1000/podman/podman.sock C:\Users\ychsu\.ssh\podman-machine-default true > podman-machine-default-root ssh://root@localhost:52156/run/podman/podman.sock C:\Users\ychsu\.ssh\podman-machine-default false # 在 ubuntu 使用的指令 podman system connection add -d \ --identity /mnt/c/Users/ychsu/.ssh/podman-machine-default \ podman-machine-default \ ssh://user@localhost:52156/run/user/1000/podman/podman.sock ``` ### 其他方法 這樣的缺點是每次都需要連進 podman 的 wsl 自己 bind `podman.sock`, 有點麻煩 1. 需要設定 Podman socket[^Podman-socket] 2. 使用 `podman system connection add <NAME> <REMOTE>` 增加遠端 server 3. 透過 `podman --remote <COMMAND>` 或是 `podman --remote -c <NAME> <COMMAND>` 使用遠端 Podman `podman system connection add` 範例: ```bash # Example for set default podman system connection add --default name unix:///mnt/wsl/podman.sock # Example-1 podman system connection add name unix:///mnt/wsl/podman.sock # Example-2 podman system connection add remote-name unix:///mnt/wsl/podman.sock ``` `podman --remote` 範例: ```bash # Example for remote to default podman --remote <COMMAND> # Example for remote non default ## 3.4.4 版本的 Podman 一定要增加 --remote 參數 ## 更高的版本應該不用, 因為有提到說用 -c 後會自動開啟 --remote 參數 ## Reference: https://docs.podman.io/en/v4.6.1/markdown/podman.1.html#connection-c podman --remote -c <NAME> <COMMAND> ``` ## 在 Ubuntu 升級 Podman[^Podman-install-on-Ubuntu-24.04] 由於 Podman 是社群開源專案, 由 RedHat 出資贊助開發, 但主要關心發布版本只有 Windows/MacOS, 所以 Ubuntu 上的版本總是是落後的版本[^No-documentation-for-installation] 簡單方法是依照這邊指令安裝最新版(remote 版本)[^Podman-install-on-Ubuntu-24.04] ```bash= sudo apt install qemu-utils qemu-system-x86 curl -OL https://github.com/containers/gvisor-tap-vsock/releases/download/v0.7.3/gvproxy-linux-amd64 # ^ or a newer from https://github.com/containers/gvisor-tap-vsock/releases sudo mkdir /usr/local/lib/podman sudo install -m 0755 gvproxy-linux-amd64 /usr/local/lib/podman/gvproxy curl -OL https://github.com/containers/podman/releases/download/v5.1.1/podman-remote-static-linux_amd64.tar.gz # ^ or a newer from https://github.com/containers/podman/releases tar xf podman-remote-static-linux_amd64.tar.gz mv bin/* # choose a binary directory in your PATH as the destination ``` 或是參考這邊[^install-on-ubuntu-22.04] ```bash= echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list curl -fsSL https://download.opensuse.org/repositories/devel:kubic:libcontainers:unstable/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_unstable.gpg > /dev/null sudo apt update sudo apt install podman ``` 再或是直接從 Podman github release 抓下來安裝(build source 或是 dpkg .deb)[^Podman-github-release] ## Podman build from source 這篇章是從頭自己 build,就不用管上面的了 主要測試在 WSL-ubuntu 上,是可以使用的 很推薦 WSL 可以自己 build,這樣可以避免要 mount ubuntu 的資料夾結果 mount 不到的情況 ==要注意 ubuntu 最少要 24.04 起跳== ### Build and install podman[^Podman-build-from-source] #### 安裝依賴 ```bash= export CRUN_VERSION=1.24 git clone --branch $CRUN_VERSION https://github.com/containers/crun.git sudo apt-get install -y make git gcc build-essential pkgconf libtool \ libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev \ go-md2man autoconf python3 automake cd crun ./autogen.sh ./configure CFLAGS='-I/usr/include/libseccomp' make sudo make install cd .. rm -rf crun ``` ```bash= sudo apt-get install -y btrfs-progs \ gcc \ git \ go-md2man \ iptables \ libassuan-dev \ libbtrfs-dev \ libc6-dev \ libdevmapper-dev \ libglib2.0-dev \ libgpgme-dev \ libgpg-error-dev \ libprotobuf-dev \ libprotobuf-c-dev \ libseccomp-dev \ libselinux1-dev \ libsystemd-dev \ make \ netavark \ passt \ pkg-config \ runc \ uidmap sudo snap install go --classic git clone https://github.com/containers/conmon cd conmon export GOCACHE="$(mktemp -d)" make sudo make podman cd .. rm -rf conmon ``` #### 檢查依賴 ```bash= crun --version go version conmon --version ``` #### 安裝 podman ```bash= export PODMAN_VERSION=v5.6.2 sudo mkdir -p /etc/containers sudo curl -L -o /etc/containers/registries.conf https://raw.githubusercontent.com/containers/image/main/registries.conf sudo curl -L -o /etc/containers/policy.json https://raw.githubusercontent.com/containers/image/main/default-policy.json sudo apt-get install -y \ libapparmor-dev \ fuse-overlayfs git clone --branch $PODMAN_VERSION https://github.com/containers/podman/ cd podman make BUILDTAGS="selinux seccomp" PREFIX=/usr sudo make install PREFIX=/usr ``` [^No-documentation-for-installation]: [Comment on No documentation for installation #21831](https://github.com/containers/podman/issues/21831#issuecomment-1971992580) [^Podman-install-on-Ubuntu-24.04]: [How to install on Ubuntu 24.04? #22921](https://github.com/containers/podman/discussions/22921) [^install-on-ubuntu-22.04]: https://github.com/containers/podman/issues/21249#issuecomment-1890753225 [^Podman-github-release]: [Podman github release](https://github.com/containers/podman/releases) [^Podman-build-from-source]:(https://podman.io/docs/installation#building-from-source)