MacOS中安装和配置Podman

孔冥夜
2023-12-01

在MacOS中,Podman的底层由QEMU虚拟机支持。虚拟机中启动了一个Linux系统,称为podman机器。可用用 podman machine 命令管理。

  • 安装podman

brew install podman

  • 启动podman虚拟机

podman machine init
podman machine start

  • 验证安装信息

podman info

  • 安装 Podman Desktop

brew install podman-desktop

  • 安装 podman-compose

pip3 install podman-compose

镜像配置文件位置

MacOS 中,podman安装在虚拟机中,修改镜像配置文件要登录虚拟机中修改。registries.conf 用于指定默认的容器仓库,拉取没有仓库名的镜像时会使用默认容器仓库,配置文件位于以下位置:

全局配置文件:

/etc/containers/registries.conf

用户配置文件:

$HOME/.config/containers/registries.conf

非root用户可以使用用户配置文件替换系统默认配置。如果设置了 CONTAINERS_REGISTRIES_CONF 环境变量,则使用该变量的设置。

容器镜像配置文件说明

配置文件为TOML格式,容器引擎会先选择用户配置文件,如果不存在就使用全局配置文件。配置例子:

# 拉取镜像时没有指定仓库地址,按这里的仓库列表顺序搜索镜像
unqualified-search-registries = ["example.com"]

[[registry]]
prefix = "example.com/foo"
insecure = false
blocked = false
location = "internal-registry-for-example.com/bar"

[[registry.mirror]]
location = "example-mirror-0.local/mirror-for-foo"

[[registry.mirror]]
location = "example-mirror-1.local/mirrors/foo"
insecure = true

[[registry]]
location = "registry.com"

[[registry.mirror]]
location = "mirror.registry.com"

当拉取 example.com/foo/image:latest 时,会按以下顺序尝试拉取,并且使用第一个存在的镜像。

  1. example-mirror-0.local/mirror-for-foo/image:latest
  2. example-mirror-1.local/mirrors/foo/image:latest
  3. internal-registry-for-example.net/bar/image:latest

挂载主机的配置到虚拟机中

每次删除虚拟机后都要重新进虚拟机修改镜像配置,可以挂载主机的配置到虚拟机中。

podman machine init  -v $HOME/.config/containers/registries.conf:/var/home/core/.config/containers/registries.conf:ro 

配置国内的镜像源

  • 登录虚拟机

podman machine ssh

  • 添加镜像配置文件

touch $HOME/.config/containers/registries.conf

  • 配置文件内容
unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "docker.io"

[[registry.mirror]]
location = "hub-mirror.c.163.com"

[[registry.mirror]]
location = "mirror.baidubce.com"

[[registry.mirror]]
location = "ustc-edu-cn.mirror.aliyuncs.com"

[[registry.mirror]]
location = "registry.docker-cn.com"

检查配置是否生效

➜  ~ podman info | grep registries -A 25
registries:
  docker.io:
    Blocked: false
    Insecure: false
    Location: docker.io
    MirrorByDigestOnly: false
    Mirrors:
    - Insecure: false
      Location: hub-mirror.c.163.com
      PullFromMirror: ""
    - Insecure: false
      Location: mirror.baidubce.com
      PullFromMirror: ""
    - Insecure: false
      Location: ustc-edu-cn.mirror.aliyuncs.com
      PullFromMirror: ""
    - Insecure: false
      Location: registry.docker-cn.com
      PullFromMirror: ""
    Prefix: docker.io
    PullFromMirror: ""
  search:
  - docker.io
store:
  configFile: /var/home/core/.config/containers/storage.conf
  containerStore:
  

参考

 类似资料: