Docker 获取 Python 镜像操作指南
1. 安装 Docker 环境
1.1 上传安装脚本(Windows → Linux)
在 Windows 的 CMD 中执行:
scp docker.sh root@10.1.1.58:~
可自行前往我的飞书下载docker.sh脚本
Docs
1.2 在 Linux 中检查文件
ls -l ~ # 确认 docker.sh 已上传到家目录
1.3 执行安装脚本
source docker.sh # 自动安装 Docker 及依赖(需提前安装 epel-release)
2. 配置 Docker 镜像加速
2.1 上传镜像配置文件
在 Windows 的 CMD 中执行:
scp daemon.json root@10.1.1.58:/etc/docker/
我的飞书里也有daemon.json,可自行下载
Docs
2.2 验证配置文件
ls /etc/docker/daemon.json # 检查文件是否存在
echo $? # 返回 0 表示文件存在
3. 启动 Docker 服务
systemctl enable --now docker # 设置开机自启并立即启动
4. 拉取 Python 镜像
4.1 查看当前镜像列表
docker images # 初始应为空或仅有基础镜像
4.2 拉取最新 Python 镜像
docker pull python # 默认拉取 latest 标签
4.3 验证镜像
docker images # 应显示 python:latest 镜像
关键说明
-
docker.sh
脚本作用:自动安装 Docker 并配置基础环境(需含epel-release
)。 -
daemon.json
文件:通常用于配置镜像加速源(如阿里云、腾讯云镜像仓库)。 -
镜像版本控制:
-
如需特定版本,使用
docker pull python:3.13
(替换版本号)。
-
常见问题
-
权限问题:若
scp
失败,检查 SSH 权限或使用sudo
。 -
镜像拉取慢:确保
daemon.json
已配置国内镜像加速源。