首页
/ Cube Studio项目中的Docker安装与配置指南

Cube Studio项目中的Docker安装与配置指南

2026-02-04 04:09:19作者:董灵辛Dennis

前言

在Cube Studio项目中,Docker作为容器化技术的核心组件,为整个平台提供了基础运行环境。本文将详细介绍在不同操作系统上安装和配置Docker的完整流程,帮助用户为Cube Studio项目搭建稳定的基础环境。

一、Ubuntu系统安装Docker

1.1 卸载旧版本Docker

在安装新版本前,建议先彻底清理旧版本:

sudo systemctl stop docker
apt-get --purge remove -y *docker*  
sudo apt-get autoremove -y
dpkg -l | grep docker

1.2 安装Docker

准备工作

sudo apt-get update -y 
sudo apt-get install -y ca-certificates curl gnupg lsb-release vim git wget net-tools

配置国内镜像源(推荐阿里云)

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
arch=amd64    # 根据架构选择amd64或arm64
sudo add-apt-repository -y "deb [arch=${arch}] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

安装指定版本Docker

sudo apt-get update
apt-cache madison docker-ce  # 查看可用版本

# 根据Ubuntu版本选择对应Docker版本
apt install -y docker-ce=5:27.0.3-1~ubuntu.20.04~focal      # Ubuntu 20.04
apt install -y docker-ce=5:27.0.3-1~ubuntu.22.04~jammy      # Ubuntu 22.04
apt install -y docker-ce=5:27.0.3-1~ubuntu.24.04~noble      # Ubuntu 24.04

# 安装docker-compose
apt install -y docker-compose

二、Ubuntu安装Kubernetes客户端

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
add-apt-repository "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main"

apt-get update -y
apt-cache madison kubectl  # 查看可用版本
apt install -y kubectl=1.24.10-00  # 安装指定版本

# 启用命令补全
apt install -y bash-completion
source <(kubectl completion bash)

三、CentOS系统安装Docker

3.1 安装Docker

# 卸载旧版本
service docker stop
rpm -qa | grep docker | xargs yum remove -y
rm -rf /usr/lib/systemd/system/docker.service

# 安装依赖
yum install -y container-selinux yum-utils 

# 配置阿里云镜像源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

yum update -y
yum list docker-ce --showduplicates  # 查看可用版本
yum install -y docker-ce  # 安装最新版
# yum install -y docker-ce-26.1.3-1.el8  # 或指定版本

systemctl start docker

3.2 安装Kubernetes客户端

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

setenforce 0
yum install -y kubectl-1.24.0 
source <(kubectl completion bash)

四、RedHat系统安装Docker

dnf update -y
dnf install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker

五、Docker配置优化

5.1 基础配置

编辑/etc/docker/daemon.json文件:

{
    "registry-mirrors": [
        "https://docker.1panel.live",
        "https://hub.rat.dev/",
        "https://docker.chenby.cn",
        "https://docker.m.daocloud.io"
    ],
    "dns": ["114.114.114.114","8.8.8.8"],
    "max-concurrent-downloads": 30,
    "data-root": "/data/docker",
    "insecure-registries":["docker.oa.com:8080"]
}

应用配置:

systemctl stop docker
systemctl daemon-reload
systemctl start docker

5.2 更改Docker存储目录

mkdir -p /data/docker/
cp -R /var/lib/docker/* /data/docker/
rm -rf /var/lib/docker

六、注意事项

  1. 如果镜像源未生效,可以在拉取镜像时手动添加阿里云镜像前缀:

    # 原命令
    docker pull rancher/rancher:v2.8.5
    # 替换为
    docker pull registry.cn-hangzhou.aliyuncs.com/rancher/rancher:v2.8.5
    
  2. 建议为Docker分配独立的存储分区,避免系统盘空间不足。

  3. 生产环境中建议使用特定版本而非最新版,以确保稳定性。

  4. 对于Kubernetes环境,建议根据集群版本选择匹配的kubectl版本。

通过以上步骤,您已经为Cube Studio项目搭建好了Docker基础环境。这些配置不仅适用于Cube Studio,也可以作为其他容器化项目的参考标准。

登录后查看全文
热门项目推荐
相关项目推荐