如何在mac上安装podman
安装 Podman 在 macOS 上
在 macOS 上安装 Podman 需要使用 Podman 的桌面客户端工具 Podman Desktop 或通过 Homebrew 安装命令行工具。
使用 Homebrew 安装 Podman:
(base) ninjamac@ninjamacdeMacBook-Air shell % brew install podman
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Auto-updated Homebrew!
Updated 3 taps (kong/deck, homebrew/core and homebrew/cask).
==> New Formulae
clang-include-graph claude-squad kargo
==> New Casks
firezone passepartout simpledemviewer slideshowerYou have 46 outdated formulae installed.==> Downloading https://ghcr.io/v2/homebrew/core/podman/manifests/5.5.0
######################################################################################## 100.0%
==> Fetching podman
==> Downloading https://ghcr.io/v2/homebrew/core/podman/blobs/sha256:8326e41b43e41f71fa6cf9c321
######################################################################################## 100.0%
==> Pouring podman--5.5.0.arm64_sequoia.bottle.tar.gz
==> Caveats
In order to run containers locally, podman depends on a Linux kernel.
One can be started manually using `podman machine` from this package.
To start a podman VM automatically at login, also install the cask
"podman-desktop".zsh completions have been installed to:/opt/homebrew/share/zsh/site-functions
==> Summary
🍺 /opt/homebrew/Cellar/podman/5.5.0: 202 files, 79.3MB
==> Running `brew cleanup podman`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)
安装完成后初始化 Podman 虚拟机(由于 macOS 不支持 Linux 容器原生运行,Podman 会创建一个轻量级虚拟机来运行容器):
(base) ninjamac@ninjamacdeMacBook-Air shell % podman machine init
Looking up Podman Machine image at quay.io/podman/machine-os:5.5 to create VM
Getting image source signatures
Copying blob d8d46037edd8 done |
Copying config 44136fa355 done |
Writing manifest to image destination
d8d46037edd878510cbcaabb4878e59e5d9eaa98d0c73eef883cd98491b08e96
Extracting compressed file: podman-machine-default-arm64.raw: done
Machine init complete
启动 Podman 虚拟机:
(base) ninjamac@ninjamacdeMacBook-Air shell % podman machine start
Starting machine "podman-machine-default"This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:podman machine set --rootfulAPI forwarding listening on: /var/folders/_0/8glqp3v96vx0_rzhlqb8g3xr0000gn/T/podman/podman-machine-default-api.sockThe system helper service is not installed; the default Docker API socket
address can't be used by podman. If you would like to install it, run the following commands:sudo /opt/homebrew/Cellar/podman/5.5.0/bin/podman-mac-helper installpodman machine stop; podman machine startYou can still connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:export DOCKER_HOST='unix:///var/folders/_0/8glqp3v96vx0_rzhlqb8g3xr0000gn/T/podman/podman-machine-default-api.sock'Machine "podman-machine-default" started successfully
验证 Podman 是否正确安装:
(base) ninjamac@ninjamacdeMacBook-Air shell % podman version
Client: Podman Engine
Version: 5.5.0
API Version: 5.5.0
Go Version: go1.24.3
Built: Wed May 14 02:59:13 2025
Build Origin: brew
OS/Arch: darwin/arm64Server: Podman Engine
Version: 5.5.0
API Version: 5.5.0
Go Version: go1.23.8
Git Commit: 0dbcb51477ee7ab8d3b47d30facf71fc38bb0c98
Built: Tue May 13 08:00:00 2025
OS/Arch: linux/arm64(base) ninjamac@ninjamacdeMacBook-Air shell % podman info
Client:APIVersion: 5.5.0BuildOrigin: brewBuilt: 1747162753BuiltTime: Wed May 14 02:59:13 2025GitCommit: ""GoVersion: go1.24.3Os: darwinOsArch: darwin/arm64Version: 5.5.0
host:arch: arm64buildahVersion: 1.40.0cgroupControllers:- cpu- io- memory- pidscgroupManager: systemdcgroupVersion: v2conmon:package: conmon-2.1.12-3.fc41.aarch64path: /usr/bin/conmonversion: 'conmon version 2.1.12, commit: 'cpuUtilization:idlePercent: 99.56systemPercent: 0.27userPercent: 0.17cpus: 4databaseBackend: sqlitedistribution:distribution: fedoravariant: coreosversion: "41"eventLogger: journaldfreeLocks: 2045hostname: localhost.localdomainidMappings:gidmap:- container_id: 0host_id: 1000size: 1- container_id: 1host_id: 100000size: 1000000uidmap:- container_id: 0host_id: 501size: 1- container_id: 1host_id: 100000size: 1000000kernel: 6.12.13-200.fc41.aarch64linkmode: dynamiclogDriver: journaldmemFree: 1293139968memTotal: 2042273792networkBackend: netavarknetworkBackendInfo:backend: netavarkdns:package: aardvark-dns-1.14.0-1.fc41.aarch64path: /usr/libexec/podman/aardvark-dnsversion: aardvark-dns 1.14.0package: netavark-1.14.0-1.fc41.aarch64path: /usr/libexec/podman/netavarkversion: netavark 1.14.0ociRuntime:name: crunpackage: crun-1.20-2.fc41.aarch64path: /usr/bin/crunversion: |-crun version 1.20commit: 9c9a76ac11994701dd666c4f0b869ceffb599a66rundir: /run/user/501/crunspec: 1.0.0+SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJLos: linuxpasta:executable: /usr/bin/pastapackage: passt-0^20250121.g4f2c8e7-2.fc41.aarch64version: |pasta 0^20250121.g4f2c8e7-2.fc41.aarch64-pastaCopyright Red HatGNU General Public License, version 2 or later<https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.remoteSocket:exists: truepath: unix:///run/user/501/podman/podman.sockrootlessNetworkCmd: pastasecurity:apparmorEnabled: falsecapabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOTrootless: trueseccompEnabled: trueseccompProfilePath: /usr/share/containers/seccomp.jsonselinuxEnabled: trueserviceIsRemote: trueslirp4netns:executable: /usr/bin/slirp4netnspackage: slirp4netns-1.3.1-1.fc41.aarch64version: |-slirp4netns version 1.3.1commit: e5e368c4f5db6ae75c2fce786e31eef9da6bf236libslirp: 4.8.0SLIRP_CONFIG_VERSION_MAX: 5libseccomp: 2.5.5swapFree: 0swapTotal: 0uptime: 0h 38m 35.00svariant: v8
plugins:authorization: nulllog:- k8s-file- none- passthrough- journaldnetwork:- bridge- macvlan- ipvlanvolume:- local
registries:search:- docker.io
store:configFile: /var/home/core/.config/containers/storage.confcontainerStore:number: 3paused: 0running: 1stopped: 2graphDriverName: overlaygraphOptions: {}graphRoot: /var/home/core/.local/share/containers/storagegraphRootAllocated: 106415992832graphRootUsed: 4448870400graphStatus:Backing Filesystem: xfsNative Overlay Diff: "true"Supports d_type: "true"Supports shifting: "false"Supports volatile: "true"Using metacopy: "false"imageCopyTmpDir: /var/tmpimageStore:number: 1runRoot: /run/user/501/containerstransientStore: falsevolumePath: /var/home/core/.local/share/containers/storage/volumes
version:APIVersion: 5.5.0BuildOrigin: 'Copr: packit/containers-podman-26126'Built: 1747094400BuiltTime: Tue May 13 08:00:00 2025GitCommit: 0dbcb51477ee7ab8d3b47d30facf71fc38bb0c98GoVersion: go1.23.8Os: linuxOsArch: linux/arm64Version: 5.5.0
配置 Podman 环境
Podman 在 macOS 上运行需要依赖虚拟机,默认使用 QEMU 运行轻量级 Linux 环境。可以通过以下命令调整虚拟机配置:
调整虚拟机 CPU 和内存(可选):
podman machine stop
podman machine set --cpus 4 --memory 8192
podman machine start
运行容器
运行一个简单的测试容器(例如 Nginx):
podman run -d -p 8080:80 --name nginx docker.io/library/nginx
验证容器是否运行:
(base) ninjamac@ninjamacdeMacBook-Air shell % podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88288e7b6232 docker.io/library/nginx:latest nginx -g daemon o... 58 seconds ago Up 58 seconds 0.0.0.0:8080->80/tcp nginx
访问运行中的容器服务(在浏览器中打开 http://localhost:8080
)。
管理容器和镜像
列出本地所有镜像:
podman images
从 Docker Hub 拉取镜像:
podman pull ubuntu:latest
进入运行中的容器:
(base) ninjamac@ninjamacdeMacBook-Air shell % podman exec -it nginx /bin/bash
root@88288e7b6232:/#
停止和删除容器:
podman stop nginx
podman rm nginx
构建自定义镜像
创建一个简单的 Dockerfile:
FROM alpine:latest
RUN apk add --no-cache python3
CMD ["python3", "--version"]
使用 Podman 构建镜像:
(base) ninjamac@ninjamacdeMacBook-Air podman % podman build -t my-python-images .
STEP 1/3: FROM alpine:latest
Resolved "alpine" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/alpine:latest...
Getting image source signatures
Copying blob sha256:d69d4d41cfe2ee680d6972795e2a1eb9e4dc4ec3b3c5e0797c9ab43bb3726fa7
Copying config sha256:2abc5e83407155714f171c293f197e1310176959e106f8ad63ffa2e7e9635d4a
Writing manifest to image destination
STEP 2/3: RUN apk add --no-cache python3
fetch https://dl-cdn.alpinelinux.org/alpine/v3.22/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.22/community/aarch64/APKINDEX.tar.gz
(1/17) Installing libbz2 (1.0.8-r6)
(2/17) Installing libexpat (2.7.1-r0)
(3/17) Installing libffi (3.4.8-r0)
(4/17) Installing gdbm (1.24-r0)
(5/17) Installing xz-libs (5.8.1-r0)
(6/17) Installing libgcc (14.2.0-r6)
(7/17) Installing libstdc++ (14.2.0-r6)
(8/17) Installing mpdecimal (4.0.1-r0)
(9/17) Installing ncurses-terminfo-base (6.5_p20250503-r0)
(10/17) Installing libncursesw (6.5_p20250503-r0)
(11/17) Installing libpanelw (6.5_p20250503-r0)
(12/17) Installing readline (8.2.13-r1)
(13/17) Installing sqlite-libs (3.49.2-r0)
(14/17) Installing python3 (3.12.11-r0)
(15/17) Installing python3-pycache-pyc0 (3.12.11-r0)
(16/17) Installing pyc (3.12.11-r0)
(17/17) Installing python3-pyc (3.12.11-r0)
Executing busybox-1.37.0-r18.trigger
OK: 49 MiB in 33 packages
--> 48a838f69aa8
STEP 3/3: CMD ["python3", "--version"]
COMMIT my-python-images
--> daf80a07597c
Successfully tagged localhost/my-python-images:latest
daf80a07597cfe6a88325506732ce1fd95a10a3fe9c44b38f0ea7a512bc1d5c9
(base) ninjamac@ninjamacdeMacBook-Air podman % podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/my-python-images latest daf80a07597c 8 seconds ago 53.8 MB
docker.io/library/alpine latest 2abc5e834071 4 days ago 8.81 MB
docker.io/library/nginx latest 997e7f255061 6 weeks ago 202 MB
运行自定义镜像:
podman run --rm my-python-image
持久化存储和数据卷
创建一个数据卷并挂载到容器:
podman volume create my_volume
podman run -d -v my_volume:/data --name volume_test alpine tail -f /dev/null
进入容器验证数据卷:
podman exec -it volume_test /bin/sh
网络配置
创建一个自定义网络:
podman network create my_network
运行容器并使用自定义网络:
podman run -d --network my_network --name web nginx
podman run -it --network my_network --name client alpine ping web
调试和日志检查
查看容器日志:
podman logs nginx
检查容器详细配置:
podman inspect nginx
监控容器资源使用:
podman stats