近期给电脑重新安装了苹果系统,开发套件不想再使用docker了,使用podman试试,未来服务器k8s也要使用podman,所以这里就可以先做个预热
brew install podman
# multipass安装需要时间长,如果有代理尽量使用代理
brew install --cask multipass
multipass version
#输出如下
#multipass 1.6.2+mac
#multipassd 1.6.2+mac
如果不实用代理,90%下载报错 超时,我这杭州电信500M家庭带宽下载都报错
最可恨的是,不使用代理的情况下,下载进度都到了99%了,竟然报 超时
multipass launch -c 2 -d 20G -m 2G -n podman
或
multipass launch -c 2 -d 20G -m 2G -n podman 21.10
primary
,那么它是默认实例,使用默认实例时,大部分命令可以省略名称multipass find
输出
Image Aliases Version Description
18.04 bionic 20220310 Ubuntu 18.04 LTS
20.04 focal,lts 20220308 Ubuntu 20.04 LTS
21.10 impish 20220309 Ubuntu 21.10
anbox-cloud-appliance latest Anbox Cloud Appliance
charm-dev latest A development and testing environment for charmers
docker latest A Docker environment with Portainer and related tools
minikube latest minikube is local Kubernetes
如何使用 ,例如安装 21.10 版本
multipass launch -c 2 -d 20G -m 2G -n podman 21.10
multipass list
输出
Name State IPv4 Image
primary Stopped -- Ubuntu 20.04 LTS
podman Running 192.168.64.2 Ubuntu 20.04 LTS
multipass shell podman
输出
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-65-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Tue Feb 23 19:43:51 PST 2021
System load: 0.01 Processes: 125
Usage of /: 19.7% of 19.21GB Users logged in: 0
Memory usage: 13% IPv4 address for enp0s2: 192.168.64.2
Swap usage: 0%
* Introducing self-healing high availability clusters in MicroK8s.
Simple, hardened, Kubernetes for production, from RaspberryPi to DC.
https://microk8s.io/high-availability
1 update can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Last login: Sun Feb 21 07:37:59 2021 from 192.168.64.1
http://mirrors.ustc.edu.cn/help/ubuntu.html
备份
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
新建编辑文件
sudo vim /etc/apt/sources.list
把如下内容保存
# 默认注释了源码仓库,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
最后更新
sudo apt-get update -y
依次执行命令
source /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add -
sudo apt-get update -y
sudo apt-get -y upgrade
sudo apt-get -y install podman
sudo systemctl enable podman.socket --now
podman --remote info
全部回车
ssh-keygen -t rsa
复制如下命令显示的字符信息
cat ~/.ssh/id_rsa.pub
multipass shell podman
然后执行命令
sudo vim /root/.ssh/authorized_keys
把 刚复制那串 字符 粘贴追加到 新建一行 后面,保存退出即可
brew install podman
官网
https://podman.io/
下载最新版本
https://github.com/containers/podman/releases/
cpu 是 intel 的所以选择
podman-remote-release-darwin_amd64.zip
添加远程链接
podman system connection add ubuntu --identity ~/.ssh/id_rsa ssh://root@192.168.64.2/run/podman/podman.sock
查看远程链接
podman system connection list
输出
Name Identity URI
ubuntu* /Users/fox/.ssh/id_rsa ssh://root@192.168.64.2:22/run/podman/podman.sock
查看是否正常
podman ps
如果正常则输出
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
如果不正常,那么进入虚拟机podman中,执行sudo chmod 777 /run/podman/podman.sock
和ln -s /run/podman /run/user/1000/podman
即可解决
multipass shell podman
编辑配置文件,并 把光标 到最后一行
sudo vim /etc/containers/registries.conf
填入如下
unqualified-search-registries = ['docker.io', 'k8s.gcr.io', 'quay.io']
[[registry]]
prefix = "docker.io"
location = "7fsmy198.mirror.aliyuncs.com"
[[registry]]
prefix = "hub.foxwho.com:5000"
location = "hub.foxwho.com:5000"
insecure = true
说明
第一个registry
中,表示把前缀为docker.io
地址的,替换为7fsmy198.mirror.aliyuncs.com
地址(不需要http或https开头),这样就是镜像加速了
第二个registry
中,私有仓库地址去掉http,并设置不使用TLS参数insecure = true
unqualified-search-registries 根据需要是否放入
[[registry]]
prefix = "docker.io"
location = "hub-mirror.c.163.com"
[[registry.mirror]]
prefix = "docker.io"
location = "dockerhub.azk8s.cn"
[[registry]]
prefix = "k8s.gcr.io"
location = "gcr.azk8s.cn/google_containers"
[[registry]]
prefix = "quay.io"
location = "quay.azk8s.cn"
在 mac终端命令行中执行 如下,主要就是重启虚拟机
multipass restart podman
mkdir -p ~/work
pwd
#输出
#/home/ubuntu
在 mac终端命令行中执行
multipass mount /Users/fox/work podman:/home/ubuntu/work
/Users/fox/work mac目录
/home/ubuntu/work 虚拟机中的目录
podman 虚拟机名称
查看挂载信息
multipass info podman
输出
Name: podman
State: Running
IPv4: 192.168.64.2
Release: Ubuntu 20.04.2 LTS
Image hash: bca04157409e (Ubuntu 20.04 LTS)
Load: 0.00 0.02 0.00
Disk usage: 3.8G out of 19.2G
Memory usage: 190.6M out of 1.9G
Mounts: /Users/fox/work => /home/ubuntu/work
UID map: 501:default
GID map: 20:default
在 mac终端命令行中执行
multipass umount /Users/fox/work podman:/home/ubuntu/work
multipass start podman
# 宿主机 传入 podman
multipass transfer ./fox.txt podman:/home/ubuntu/fox.txt
# podman 传到 宿主机
cd ~/Downloads
multipass transfer podman:/home/ubuntu/test.txt ./fox2.txt
停止虚拟机
multipass stop podman
启动虚拟机
multipass start podman
重启虚拟机
multipass restart podman
查看列表
multipass list
挂起虚拟机
multipass list
进入虚拟机
multipass shell podman
不登陆虚拟机执行一个命令
multipass exec podman top
查看详细信息
multipass info podman
批量删除带有 fox 的镜像
podman images | grep fox | awk '{print $1":"$2}' | xargs podman rmi
批量删除所有镜像
podman rmi -f $(podman images -qa)
删除镜像缓存
podman system prune --volumes
以下所有都会删除
- 所有停止的容器
- 所有不被任何一个容器使用的网络
- 所有不被任何一个容器使用的volume
- 所有无实例的镜像
彻底清理所有已删除实例
multipass purge
multipass launch --name podman --cloud-init dev.yaml
例如:我想在创建后,自动安装 vim curl 等套件
dev.yaml 文件内容如下:
#cloud-config
runcmd:
- sudo apt-get install -y vim
- sudo apt-get install -y curl
文件必须
#cloud-config
开头。案例https://cloudinit.readthedocs.io/en/latest/topics/examples.html
执行拉取生成镜像命令
podman run -it -d --name mariadb -p 3306:3306 -e MARIADB_ROOT_PASSWORD=root mariadb:latest
查看
podman ps
输出
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b4eb533607b9 docker.io/library/mariadb:latest mariadbd 43 seconds ago Up 42 seconds ago 0.0.0.0:3306->3306/tcp mariadb
sudo apt-get install python3-pip
pip3 install podman-compose
执行命令,在出现的提示中输入要设置root用户密码, 设置2次
sudo passwd root
切换root 用户
su root
cd ~
alias docker=podman
alias docker-compose=podman-compose
multipass start podman
#报错
start failed: The following errors occurred:
Instance stopped while starting
每个人的情况不一样,解决方法也不一样。
没找到怎么查看虚拟机启动日志,那么直接查看进程信息。
通过查看 ps aux | grep multipass
,输出/Library/Application Support/com.canonical.multipass/bin/hyperkit -c 2 -m 2048M -u -A -H -U abe31bcf-b59f-3265-82fb-97dde407366c -s 0:0,hostbridge -s 2:0,virtio-net -s 5,virtio-rnd -s 31,lpc -l com1,autopty=/var/root/Library/Application Support/multipassd/vault/instances/podman/pty,log=/Library/Logs/Multipass/podman-hyperkit.log -s 1:0,。。。。。
,其中有 log=/Library/Logs/Multipass/podman-hyperkit.log
这个是我想要的日志。
通过cd
或者进入目录查看该文件日志,发现没权限,
立即设置权限 sudo chmod -R 777 /Library/Logs/Multipass/
,设置完权限后,嘿 虚拟机Podman 启动成功了。
如果还是不成功,那么,执行如下操作
主要意思是 重启multipass
ps -ef | grep multipass|awk '{print "kill -9 "$2}'|sh
multipass start podman
嘿,有时候使用上面2个命令不可以,必须一条一条执行
# 查看得出 pid ,假设 pid 为 1705
ps -ef | grep multipass
#删除他
kill -9 1705
#启动podman
multipass start podman
参考
https://www.cnblogs.com/ryanyangcs/p/14024273.html
https://blog.csdn.net/jaket5219999/article/details/113637306
https://www.techrepublic.com/article/how-to-install-podman-on-ubuntu/
https://blog.csdn.net/weixin_39521520/article/details/111165006
https://www.bboy.app/2020/01/17/%E4%BD%BF%E7%94%A8Multipass%E5%9C%A8%E4%BD%A0%E7%9A%84windows%E6%88%96%E8%80%85mac%E7%94%B5%E8%84%91%E4%B8%8A%E5%BF%AB%E9%80%9F%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AAUbuntu%E8%99%9A%E6%8B%9F%E6%9C%BA/