Docker 部署 Rancher 指定镜像仓库

docker 启动的 rancher 默认会走公网获取镜像,添加了 CATTLE_SYSTEM_DEFAULT_REGISTRY 的话,helm-operation 使用的 rancher/shell 等还是会走到公网,如果要所有镜像都是用 private registry,可以通过下面的方式。

准备 private registry 认证的配置文件和 k3s 配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mkdir -p /etc/rancher/k3s

cat <<EOF > /etc/rancher/k3s/registries.yaml
configs:
"harbor.warnerchen.com":
auth:
username: xxx
password: xxx
tls:
insecure_skip_verify: true
EOF

cat <<EOF > /etc/rancher/k3s/config.yaml
system-default-registry: harbor.warnerchen.com
EOF

启动 rancher:

1
2
3
4
5
6
7
8
9
docker run -d --restart=unless-stopped --name rancher \
-v /var/lib/rancher:/var/lib/rancher \
-v /etc/rancher/k3s/registries.yaml:/etc/rancher/k3s/registries.yaml:ro \
-v /etc/rancher/k3s/config.yaml:/etc/rancher/k3s/config.yaml:ro \
-e CATTLE_BOOTSTRAP_PASSWORD=RancherForFun \
-e CATTLE_SYSTEM_DEFAULT_REGISTRY=harbor.warnerchen.com \
-p 80:80 -p 443:443 \
--privileged \
harbor.warnerchen.com/prime/rancher:v2.7.15-ent
Author

Warner Chen

Posted on

2024-11-28

Updated on

2024-11-28

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.