当前位置: 首页 > news >正文

【容器化】Linux环境Docker在线与离线安装手册

一、安装前准备

系统要求

  • 支持64位CentOS 7/8、Ubuntu 16.04+、Debian 9+等发行版。
  • Linux内核版本≥3.10(通过uname -r查看)。

Docker 19.03:支持 Linux内核3.10及以上。

Docker 20.10:虽然仍然可以在3.10上运行,但建议使用内核4.0及以上以获得更好的性能和功能。

  • 建议使用root权限或sudo命令执行安装。

二、在线安装流程

方式1:一键脚本安装(推荐)

# 官方脚本(默认使用阿里云镜像源)
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

方式2:手动分步安装

1. 更新软件源与依赖包

sudo yum update -y 
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

2. 添加Docker官方仓库

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo  # 替换为阿里云镜像

3. 安装Docker引擎

sudo yum install -y docker-ce docker-ce-cli containerd.io

4. 启动服务并设置自启

sudo systemctl start docker 
sudo systemctl enable docker

三、离线安装流程

1. 下载离线包

  • 访问Docker官方下载页获取docker-<version>.tgz

  • 示例版本:docker-27.1.0.tgz

2. 解压并部署文件

tar -xvf docker-27.1.0.tgz
sudo cp docker/* /usr/bin/

    3. 注册系统服务

    创建/etc/systemd/system/docker.service文件,内容参考《linux中离线安装docker》中配置文件模板,保存后执行:

    vi /etc/systemd/system/docker.service

    docker.service中的内容为:

    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network-online.target firewalld.service
    Wants=network-online.target
    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    ExecStart=/usr/bin/dockerd
    ExecReload=/bin/kill -s HUP $MAINPID
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    # Uncomment TasksMax if your systemd version supports it.
    # Only systemd 226 and above support this version.
    #TasksMax=infinity
    TimeoutStartSec=0
    # set delegate yes so that systemd does not reset the cgroups of docker containers
    Delegate=yes
    # kill only the docker process, not all processes in the cgroup
    KillMode=process
    # restart the docker process if it exits prematurely
    Restart=on-failure
    StartLimitBurst=3
    StartLimitInterval=60s
    [Install]
    WantedBy=multi-user.target

    4. 启动docker

    chmod +x /etc/systemd/system/docker.service #设置权限
    systemctl daemon-reload
    systemctl start docker            #启动Docker

    5. 验证状态

    systemctl status docker  #查看Docker状态
    docker -v                #查看Docker版本

    四、验证安装

    检查版本信息

    docker version # 显示Client和Server版本

    运行测试容器

    sudo docker run hello-world # 输出"Hello from Docker!"即成功

    五、常见问题解决

    权限问题

    sudo groupadd docker  # 创建docker用户组(若不存在)
    sudo usermod -aG docker $USER  # 将当前用户加入组
    newgrp docker  # 刷新组权限

    镜像加速配置

    编辑/etc/docker/daemon.json,添加:https://registry.cn-hangzhou.aliyuncs.com

    {"registry-mirrors": ["https://<your-mirror-id>.mirror.aliyuncs.com"]}

    重启服务

    sudo systemctl restart docker

    http://www.xdnf.cn/news/231391.html

    相关文章:

  1. vscode中设置eslint保存时自动格式化未生效
  2. 网易爆米花 1.8.8 | 免费无广告,支持多网盘聚合和智能刮削技术,提供顶级画质和逼真音效的影视管理应用
  3. 【大模型系列篇】Qwen3开源全新一代大语言模型来了,深入思考,更快行动
  4. Python 用一等函数重新审视“命令”设计模式
  5. CMake解析参数用法示例
  6. 【模型量化】量化基础
  7. 大连理工大学选修课——机器学习笔记(7):集成学习及随机森林
  8. 三生原理与中华文明标识体系的关系?
  9. vs2019编译occ7.9.0时,出现fatal error C1060: compiler is out of heap space
  10. C++(初阶)(十六)——set
  11. YOLO视觉模型可视化训练与推理测试工具
  12. 嵌入式中常用的算法介绍
  13. (Go Gin)Gin学习笔记(五)会话控制与参数验证:Cookie使用、Sessions使用、结构体验证参数、自定义验证参数
  14. 自动驾驶-一位从业两年的独特视角
  15. 2025年-redis(p1-p10)
  16. Kotlin与Jetpack Compose的详细使用指南
  17. 高级java每日一道面试题-2025年4月30日-基础篇[反射篇]-如何防止你的类被通过反射非法实例化?
  18. PCI总线数据采集卡 32路多功能异步模拟量信号采集卡
  19. 如何在 Go 中实现各种类型的链表?
  20. 硬盘分区丢失≠末日!3步逻辑恢复法+物理修复全流程图解
  21. 大数据应用开发和项目实战-Seaborn
  22. 使用通义千问大模型做结构化输出报错的分析
  23. ubantu部署yolov5(第四集:模型加速)
  24. 正点原子STM32H743单片机实现ADC多通道检测
  25. k8s平台:手动部署Grafana
  26. SQL命令二:SQL 高级查询与特殊算法
  27. Git从入门到精通-第一章-基础概念
  28. 软件性能测试有多关键?能找出潜在问题并确保其顺利运行吗?
  29. [250430] Kali Linux 存储库密钥丢失导致所有用户无法正常更新 APT
  30. JavaScript:从JS的执行机制到location对象