跳过正文
  1. Posts/

Lima

·430 字·3 分钟· ·
XhstormR
作者
XhstormR
INTJ
目录

https://github.com/lima-vm/lima

https://github.com/containers/podman

https://github.com/docker/cli

Lima VM + Podman Runtime + Docker CLI
#

limactl create --name=default template:podman
limactl edit --mount-writable # Make all mounts writable
limactl edit --mount '/Users/leo/Documents/IdeaProjects:w'
limactl start default
limactl ls

export DOCKER_HOST=unix:///Users/leo/.lima/default/sock/podman.sock
docker info
docker ps -a

docker run -it -v '/Users/leo/Documents/IdeaProjects:/work' -w /work sina.dev/library/fedora:latest bash

透明代理容器网络
#

虚拟机 (Guest)
#

lima.yaml
1provision:
2    - mode: system
3      file: "{{.Dir}}/sing-box/tun-provisioning.sh"
4
5mounts:
6    - location: "{{.Dir}}/sing-box"
7      mountPoint: /var/lib/sing-box
sing-box/tun-provisioning.sh
 1#!/bin/bash
 2set -eux -o pipefail
 3
 4export PATH="~/.pixi/bin:$PATH"
 5
 6if ! dnf list --installed terra-release >/dev/null 2>&1; then
 7    dnf install -y --nogpgcheck --repofrompath 'terra,https://repos.fyralabs.com/terra$releasever' terra-release
 8
 9    echo "terra-release added"
10fi
11
12if ! command -v sing-box >/dev/null 2>&1; then
13    dnf install -y pixi
14    pixi global install sing-box
15
16    echo "sing-box installed"
17fi
18
19if ! systemctl is-active --quiet sing-box; then
20    chcon -t bin_t `type -P sing-box` # SELinux Enforcing
21    systemd-run --unit=sing-box `type -P sing-box` run -c config.json -D /var/lib/sing-box
22    systemctl status sing-box
23
24    echo "sing-box started"
25fi
sing-box/config.json
 1{
 2    "log": {
 3        "level": "info"
 4    },
 5    "inbounds": [
 6        {
 7            "type": "tun", // 透明代理
 8            "address": ["172.19.0.1/30"],
 9            "auto_route": true,
10            "strict_route": true
11        }
12    ],
13    "outbounds": [
14        {
15            "tag": "自选",
16            "type": "socks",
17            "server": "host.lima.internal",
18            "server_port": 1080,
19            "domain_resolver": "dns-local" // 用于本地解析 outbound.server 的域名 host.lima.internal,防止解析死循环
20        },
21        {
22            "tag": "直连",
23            "type": "direct"
24        }
25    ],
26    "dns": {
27        "strategy": "ipv4_only",
28        "servers": [
29            {
30                "tag": "dns-remote",
31                "type": "https",
32                "server": "9.9.9.9",
33                "detour": "自选"
34            },
35            {
36                "tag": "dns-local",
37                "type": "local"
38            }
39        ]
40    },
41    "route": {
42        "find_process": true,
43        "auto_detect_interface": true,
44        "default_domain_resolver": "dns-remote",
45        "rules": [
46            {
47                "action": "sniff"
48            },
49            {
50                "protocol": "dns",
51                "action": "hijack-dns"
52            },
53            {
54                "ip_is_private": true,
55                "outbound": "直连"
56            }
57        ]
58    }
59}

宿主机 (Host)
#

config.json
 1{
 2    "inbounds": [
 3        {
 4            "type": "mixed", // SOCKS5 HTTP 代理
 5            "listen": "127.0.0.1",
 6            "listen_port": 1080,
 7            "set_system_proxy": false
 8        }
 9    ]
10}

smolvm
#

smolvm machine run --net --image sina.dev/library/fedora:latest -it --oci-cache -- bash

kern
#

只支持 Linux 宿主机,可以运行在 Lima VM 中。

kern info
kern ps -a
kern images
kern stats
kern history
kern prune
kern doctor
kern top

kern box --net --image sina.dev/library/fedora:latest -it --verbose -- bash

kern compose docker-compose.yml up
kern compose docker-compose.yml stop

Kata Containers
#

Reference
#