1. 将debian12 改为支持中文显示

export LANG=zh_CN.UTF-8
source /etc/profile

2. 改为清华仓库镜像

echo -e "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware\ndeb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware\ndeb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware\ndeb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
echo "Acquire::http::Pipeline-Depth "0";" > /etc/apt/apt.conf.d/99nopipelining

3. 安装docker

apt update
apt upgrade -y
apt install curl vim wget gnupg dpkg apt-transport-https ca-certificates

# 导入清华的dockerce镜像源
curl -sS https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=(dpkg−−print−architecture)signed−by=/usr/share/keyrings/docker−ce.gpg]https://mirrors.tuna.tsinghua.edu.cn/docker−ce/linux/debian(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian (lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

# 开始安装docker
apt update
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 查看docker版本
docker version

4. 安装docker-compose

# 可以自行选择github的最新版本
curl -L https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-linux-x86_64 > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version

5. 修改docker配置,防止日志爆满

cat > /etc/docker/daemon.json << EOF
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "20m",
        "max-file": "3"
    },
    "ipv6": true,
    "fixed-cidr-v6": "fd00:dead:beef:c0::/80",
    "experimental":true,
    "ip6tables":true
}
EOF

6. docker重启并设置开机自启动

systemctl restart docker
systemctl enable docker

7. 配置镜像加速

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://[你自己的阿里云容器加速地址].mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

关于阿里云的容器镜像加速在阿里云官网可以免费个人申请一个 教程见 阿里云容器镜像加速服务申请

8. 安装ssh工具(只安装docker的在上一步就已经结束了,安装ssh只是我个人使用)

1. 安装ssh工具(debian12为例)

apt install openssh-server

2. 在ssh配置文件(/etc/ssh/sshd_config)追加配置

# 打开配置文件
nano /etc/ssh/sshd_config
# 在末尾追加
PermitRootLogin yes
PasswordAuthentication yes

3. 重启服务

/etc/init.d/ssh restart
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐