【转】在特定环境中安装指定版本的Docker

本文介绍如何在特定环境中安装指定版本的Docker,包括通过手动安装和使用脚本一键安装两种方式,并提供具体操作步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


百度短网址: http://dwz.cn/6b3WKA 

 

在特定环境中安装指定版本的Docker

原创 2017-06-26 Mike 运维之美

通常用官方提供的安装脚本或软件源安装都是安装的比较新 Docker 版本,有时我们需要在一些特定环境的服务器上安装指定版本的 Docker。今天我们就来讲一讲如何安装指定版本的 Docker 。

 

1.通过手动安装

1.1 增加软件安装源

· 

Ubuntu

导入软件仓库证书

$ apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

新增一个 docker.list 文件,在其中增加对应的软件安装源。

# Ubuntu Precise

deb https://apt.dockerproject.org/repo ubuntu-precise main

 

# Ubuntu Trusty

deb https://apt.dockerproject.org/repo ubuntu-trusty main

 

# Ubuntu Xenial

deb https://apt.dockerproject.org/repo ubuntu-xenial main

Ubuntu 16.04 为例:

$ vim  /etc/apt/sources.list.d/docker.list

 

deb https://apt.dockerproject.org/repo ubuntu-xenial main

· 

CentOS

新增一个 docker.repo 文件,在其中增加对应的软件安装源。 这里以 CentOS 7 为例:

$ cat >/etc/yum.repos.d/docker.repo <<EOF

[dockerrepo]

name=Docker Repository

baseurl=https://yum.dockerproject.org/repo/main/centos/7

enabled=1

gpgcheck=1

gpgkey=https://yum.dockerproject.org/gpg

EOF

1.2 更新软件源

Ubuntu

$ apt-get update

· 

CentOS

$ yum makecache

1.3 显示软件源中所有Docker软件包安装信息

Ubuntu

$ apt-cache policy docker-engine

docker-engine:

  Installed: (none)

  Candidate: 17.05.0~ce-0~ubuntu-xenial

  Version table:

     17.05.0~ce-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     17.04.0~ce-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     17.03.1~ce-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     17.03.0~ce-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.13.1-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.13.0-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.6-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.5-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.4-0~ubuntu-xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.3-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.2-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.1-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.12.0-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.11.2-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.11.1-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

     1.11.0-0~xenial 500

        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

· 

CentOS

$ yum provides docker-engine

1.4 移除其它版本Docker

如果之前存在其它版本的Docker,可以使用以下命令先移出:

Ubuntu

$ apt-get purge docker-engine


CentOS

$ yum remove docker-engine

1.5 安装指定版本Docker

根据实际情况,选定要安装的 Docker 版本进行安装。这里以安装 1.13.1 版本为例:

· 

Ubuntu

如果 Ubuntu 为 14.04 建议先装上以下两个软件包。

$ apt-get install \

    linux-image-extra-$(uname -r) \

    linux-image-extra-virtual

$ apt-get install docker-engine=1.13.1-0~ubuntu-xenial

· 

CentOS

$ yum install docker-engine-1.13.1-1.el7.centos.x86_64

1.6 验证Docker版本

$ docker -v

Docker version 1.13.1, build 092cba3

2.通过脚本一键安装

如果觉得手动安装太过复杂,也可以直接使用下面的脚本一键安装:

$ curl -sSL https://github.com/gitlawr/install-docker/blob/1.0/<docker-version-you-want>.sh?raw=true | sh

或者:

$ wget -qO- https://github.com/gitlawr/install-docker/blob/1.0/<docker-version-you-want>.sh?raw=true | sh

使用需要的 Docker 版本替换以下脚本中的 <docker-version-you-want>,目前该脚本支持的 Docker 版本:

1.10.3

1.11.2

1.12.1

1.12.2

1.12.3

1.12.4

1.12.5

1.12.6

1.13.0

1.13.1

17.03.0

17.03.1

17.04.0

注:脚本使用 USTC 的软件包仓库,已基于 Ubuntu_Xenial , CentOS7  以及 Debian_Jessie 完成测试。脚本会根据 Linux 发行版有少许区别,比如 Ubuntu 16.04 下不兼容 Docker-1.10.3。

这里以安装 1.13.1 为例:

 

参考文档

http://www.google.com
http://www.cnrancher.com/install-docker/
http://www.cnblogs.com/yanghuahui/p/4874937.html
https://blog.phpgao.com/docker_install_specific_version.html

<think>好的,我现在需要帮助用户在特定操作系统上安装指定版本Docker。用户提到了不同的引用内容,包括CentOS和Ubuntu的例子,所以我要分别处理这两个系统。首先,我需要回忆安装指定版本Docker的步骤,确保每个操作系统的命令正确无误。 对于CentOS,根据引用[2],用户需要先添加Docker仓库,然后使用yum安装指定版本。步骤包括设置仓库,列出可用版本,选择并安装。记得开启Docker服务并验证安装。这里要注意版本号的格式,比如18.06.1.ce-3.el7。 然后是Ubuntu系统,引用[3]提到需要先更新和升级系统,然后添加Docker的GPG密钥和仓库。这里可能使用apt-get来安装特定版本,但步骤可能不同,需要先apt-cache查找可用版本,然后使用apt-get install指定版本号,比如docker-ce=18.06.1~ce~3-0~ubuntu。 另外,用户可能需要通用步骤,比如验证安装是否成功,使用docker --version或者运行hello-world容器。还要提醒用户注意版本号的正确性,以及不同操作系统的包管理器差异。 需要确保命令中的占位符如<VERSION_STRING>被正确替换,避免用户直接复制时出错。同时,注意不同系统的服务管理命令,比如systemctl在CentOS和Ubuntu中的使用可能相似,但路径或依赖可能不同。 最后,生成的相关问题应该覆盖不同系统、版本查询方法、回退版本和验证安装的方法,确保用户有其他疑问时可以找到答案。</think>### 分步指南:安装指定版本Docker #### 1. **CentOS/RHEL 系统安装步骤** **步骤 1:添加 Docker 仓库** ```bash sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo ``` **步骤 2:列出可用版本** ```bash yum list docker-ce --showduplicates | sort -r ``` 输出示例: ``` docker-ce.x86_64 3:20.10.9-3.el7 docker-ce-stable docker-ce.x86_64 3:20.10.8-3.el7 docker-ce-stable ``` 选择所需版本(如 `20.10.9`)[^2]。 **步骤 3:安装指定版本** ```bash sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io # 示例: sudo yum install docker-ce-20.10.9 docker-ce-cli-20.10.9 containerd.io ``` **步骤 4:启动并验证** ```bash sudo systemctl start docker sudo docker run hello-world # 验证是否成功 ``` --- #### 2. **Ubuntu/Debian 系统安装步骤** **步骤 1:更新系统并安装依赖** ```bash sudo apt update sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common ``` **步骤 2:添加 Docker GPG 密钥和仓库** ```bash curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` **步骤 3:列出可用版本** ```bash apt-cache policy docker-ce ``` 输出示例: ``` Candidate: 5:20.10.9~3-0~ubuntu-focal Version table: 5:20.10.9~3-0~ubuntu-focal 500 ``` **步骤 4:安装指定版本** ```bash sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> # 示例: sudo apt-get install docker-ce=5:20.10.9~3-0~ubuntu-focal docker-ce-cli=5:20.10.9~3-0~ubuntu-focal ``` **步骤 5:验证安装** ```bash docker --version # 应显示安装版本号,例如 Docker version 20.10.9[^1] ``` --- #### 3. **通用注意事项** - **版本号格式**:需严格匹配仓库中的版本字符串(如 `20.10.9` 或 `5:20.10.9~3-0~ubuntu-focal`)。 - **降级版本**:若需回退版本,先卸载当前版本安装旧版。 - **依赖兼容性**:某些旧版本可能与新系统不兼容,建议测试环境先行。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值