Skip to content

Instantly share code, notes, and snippets.

@zh4n7wm
Created March 4, 2021 09:29
Show Gist options
  • Save zh4n7wm/ea061eedaa2363c7bcd89e4ea649f839 to your computer and use it in GitHub Desktop.
Save zh4n7wm/ea061eedaa2363c7bcd89e4ea649f839 to your computer and use it in GitHub Desktop.
podman tips

下面介绍 podmanpodman-compose 安装及使用。

文中只列出了 Ubuntu 20.04 系统的安装过程。

安装

设置源

source /etc/os-release
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key -O- | sudo apt-key add -
sudo apt-get update -qq
sudo apt-get -qq --yes install podman

安装 crun

sudo apt-get -y install crun

安装 podman

sudo apt-get -y install podman

检查是否安装成功:

podman info

解决墙内网络问题

  1. 配置代理,让 podman 通过代理下载 container image

参考:question: how-to download a container image using a proxy

export http_proxy='http://your-ip:port'
export https_proxy='http://your-ip:port'
  1. 使用 dockerhub mirror

修改 registry,编辑 /etc/containers/registries.conf

unqualified-search-registries = ['docker.io', 'dockerhub.qingcloud.com', 'k8s.gcr.io', 'quay.io']

[[registry]]
prefix = 'docker.io'
location = 'hub-mirror.c.163.com'

[[registry.mirror]]
prefix = "docker.io"
location = 'hub-mirror.c.163.com'

[[registry.mirror]]
prefix = "docker.io"
location = "mirror.baidubce.com"

更多信息请 man containers-registries.conf

注:这些 dockerhub mirror 随时都有可能不再工作,可能还是代理靠谱些。

安装 podman-compose

直接用Github上的最新版本,不建议用 pip install podman-compose 安装。

sudo curl -o /usr/local/bin/podman-compose https://raw.githubusercontent.com/containers/podman-compose/devel/podman_compose.py
sudo chmod +x /usr/local/bin/podman-compose

注:

  • 确保 /usr/local/bin$PATH 环境变量
  • 安装后使用和 docker-compose 基本一样的

安装 buildah

sudo apt-get -y install buildah

实践

podman

通过 podman 运行 PostgreSQL

podman pull postgres:alpine
podman pod create -n postgres-pod -p 5432:5432
podman volume create pgdata
podman run --name postgres --pod postgres-pod -e POSTGRES_PASSWORD=secret -v pgdata:/var/lib/postgresql/data -d postgres:alpine

# 查看服务是否起来
podman ps

# 进入 postgres 容器
podman exec -it postgres bash

# podman 命令基本和 docker 差不多,所以官网推荐 `alias docker=podman`

通过 podman-compose 运行 atom

cd deploy/flying-pub-prod/rust
mkdir -p /data/atom-postgres  # docker-compose.yml 中用它做 postgres volume
podman-compose up -d

FAQ

  1. 能否在 MacOS/Windows 上运行 podman

The Podman service runs only on Linux platforms, however a REST API and clients are currently under development which will allow Mac and Windows platforms to call the service. There is currently a RESTful based remote client which runs on Mac or Windows platforms that allows the remote client to talk to the Podman server on a Linux platform. In addition to those clients, there is also a Mac client.

Podman Remote clients for MacOS and Windows

也就是只能在 MacOS/Windows 上运行 podman client,让它去连接运行在 Linux 上的 podman api service,上面连接中有指令。 (Docker 配置下 DOCKER_HOST 环境变量也能这样玩)

  1. switch to cgroup v2

archlinux, Switching to cgroups v2

ubuntu

* kernel > 5.2 (ubuntu 20 LTS kernel 5.4)
* edit `/etc/default/grub`, GRUB_CMDLINE_LINUX_DEFAULT=cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=1
* update-grub
* check: ls /sys/fs/cgroup
  1. rootless

https://github.com/containers/podman/blob/master/docs/tutorials/rootless_tutorial.md

check subgid/subuid

cat /etc/subgid
cat /etc/subuid
  1. 和 docker 到底有啥区别
  1. How to use crun with docker?

How to use crun with docker?

  1. crun vs runc

An introduction to crun, a fast and low-memory footprint container runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment