Skip to content

拉取 Rancher 镜像

shell
docker pull rancher/rancher:latest

运行 Rancher 容器

shell
docker run -d --name rancher --restart=unless-stopped --privileged -p 80:80 -p 443:443 rancher/rancher:latest

说明 -d:在后台运行容器。 --name rancher:容器名称为 rancher。 --restart=unless-stopped:容器会在 Docker 重启时自动启动,除非手动停止。 --privileged:以特权模式运行容器,这是 Rancher 2.0 所需的。 -p 80:80:将主机的 80 端口映射到容器的 80 端口。 -p 443:443:将主机的 443 端口映射到容器的 443 端口。

使用 docker-compose 部署 rancher

在指定的目录下创建如下的一个 docker-compose.yaml 文件

yaml
version: "3.7"

services:
  rancher:
    image: rancher/rancher:latest
    container_name: rancher
    restart: unless-stopped
    privileged: true
    ports:
      - "9018:80"
      - "9443:443"
    environment:
      - CATTLE_BOOTSTRAP_PASSWORD=thisIsDemoPass@word

使用 docker-compose up -d 命令运行即可

常见的 rancher 部署的问题

在运行 rancher 之后,服务并没有启动起来,通过 docker logs -f 容器的 ID 查看运行的日志会输出下面的这样的错误

Waiting for server to become available: Get "https://127.0.0.1:6444/version?timeout=15m0s": dial tcp 127.0.0.1:6444: connect: connection refused`
rancher k3s exited with: exit status 1

原因:这是在 centos8.2 平台下出现的问题,加载内核模块 iptable_filter

解决的办法:

  • modprobe iptable_filter
  • lsmod | grep ip

具体文档请参考:https://blog.csdn.net/u011197085/article/details/138143476

https://juejin.cn/post/7301577141891088435