总有人间一两风,填我十万八千梦

Ubuntu下使用阿里云Aliyun镜像安装Docker容器(CE版)

软件技巧 Zero、J 1017℃ 0评论

#步骤1(设置一下软件源)

设置你的软件源为阿里云,这一步不是必须的,但是可以为你后续下载一些其他的依赖文件的时候加速,下面是一份Ubuntu下阿里云软件源的配置。备份一下你的/etc/apt/sources.list ,然后将/etc/apt/sources.list内容修改为如下的内容,#号表示的是注释,你可以移除这些注释。如果你是终端用户,你可以直接使用 nano /etc/apt/sources.list 对源配置文件进行修改(个人感觉nano比vi更舒服)。

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb https://mirrors.aliyun.com/ubuntu bionic main restricted
# deb-src https://mirrors.aliyun.com/ubuntu bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb https://mirrors.aliyun.com/ubuntu bionic-updates main restricted
# deb-src https://mirrors.aliyun.com/ubuntu bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu bionic universe
# deb-src https://mirrors.aliyun.com/ubuntu bionic universe
deb https://mirrors.aliyun.com/ubuntu bionic-updates universe
# deb-src https://mirrors.aliyun.com/ubuntu bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb https://mirrors.aliyun.com/ubuntu bionic multiverse
# deb-src https://mirrors.aliyun.com/ubuntu bionic multiverse
deb https://mirrors.aliyun.com/ubuntu bionic-updates multiverse
# deb-src https://mirrors.aliyun.com/ubuntu bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb https://mirrors.aliyun.com/ubuntu bionic-security main restricted
# deb-src https://mirrors.aliyun.com/ubuntu bionic-security main restricted
deb https://mirrors.aliyun.com/ubuntu bionic-security universe
# deb-src https://mirrors.aliyun.com/ubuntu bionic-security universe
deb https://mirrors.aliyun.com/ubuntu bionic-security multiverse

#步骤2(更新一下apt软件源信息)

设置完软件源之后,使用命令 sudo apt update 更新一下软件源信息。

root@dev:~# sudo apt update
Hit:1 http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic InRelease
Hit:2 https://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:3 https://mirrors.aliyun.com/ubuntu bionic-updates InRelease
Hit:4 https://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Hit:5 https://mirrors.aliyun.com/ubuntu bionic-security InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
21 packages can be upgraded. Run 'apt list --upgradable' to see them.

#步骤3 移除旧的Docker安装版本

旧版本的docker被称作docker,docker.io或者docker-engine,如果你曾经安装过这些,请卸载他们,使用命令 sudo apt-get remove docker docker-engine docker.io containerd runc ,如果你确定你没有安装旧的版本,可以忽略这一步。

root@dev:~# sudo apt-get remove docker docker-engine docker.io containerd runc
Reading package lists... Done
Building dependency tree
Reading state information... Done
.......................
....卸载的包的信息.....
.......................

#步骤4(安装一些必要的依赖库)

这一步主要是安装一些必要的依赖库,这也就是为什么在步骤1中建议更改一下软件源,Ubuntu的默认国内cn源不好用。使用命令 sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common ,这些软件包可以允许apt安装的时候可以使用HTTPS协议访问软件仓库。

root@dev:~# sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
......................
.....安装信息,略.....
......................

#步骤5 安装GPG证书(这里使用阿里云的)

官方中提供的是地址是https://download.docker.com/linux/ubuntu/gpg,这里我们使用阿里云的地址 ,使用命令 curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - ,安装成功后,会显示一个OK。

root@dev:~# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
OK

完成之后,通过搜索证书指纹的最后8个字节,可以验证当前安装的证书,使用命令 sudo apt-key fingerprint 0EBFCD88

root@dev:~# sudo apt-key fingerprint 0EBFCD88
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

#步骤6 添加阿里云Docker的软件源

使用命令 sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" ,docker官方提供的软件源地址是https://download.docker.com/linux/ubuntu,这里我们使用的是aliyun的,注意命令中stable后面的引号,这个stable表示稳定版,。

root@dev:~# sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
Hit:1 http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic InRelease
Hit:2 https://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:3 https://mirrors.aliyun.com/ubuntu bionic-updates InRelease
Hit:4 https://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Hit:5 https://mirrors.aliyun.com/ubuntu bionic-security InRelease
Reading package lists... Done

步骤 7: 更新并安装 Docker-CE

使用命令 sudo apt-get update 更新一下软件源信息,然后使用命令 sudo apt-get install docker-ce 安装docker-ce。

root@dev:~# sudo apt update
....................
...更新的信息,略....
....................
root@dev:~# sudo apt install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce-cli libltdl7 pigz
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce docker-ce-cli libltdl7
  pigz
0 upgraded, 7 newly installed, 0 to remove and 21 not upgraded.
Need to get 85.8 MB of archives.
After this operation, 385 MB of additional disk space will be used.
Do you want to continue? [Y/n]    

#这里将会询问是否继续安装
#我当前下载的默认最新版的docker安装需要385MB的磁盘空间,输入Y确认安装
                        

安装完毕之后,使用命令 service docker status 看一下docker服务的状态,如果显示了绿色的 active (running)那就表示正常启动了(默认安装后自动启动),否则你可以尝试使用命令 service docker start 启动一下看看是否出现了什么错误。

绿色的Active(running)表示正常运行

步骤 8: 测试安装一个hello-world

使用命令 docker run hello-world ,如果你的计算机可以正常连接到docker的https://hub.docker.com,就会自动下载hello-world,然后运行,会显示Hello From Docker!的信息。

正常运行HelloWord

如果很不幸,你的网络无法正常连接hub.docker.com,此时你会下载失败,此时我建议你使用阿里云的加速功能,操作步骤见 www.youranshare.com/push/topics/softuse/6806.html

转载请注明:悠然品鉴 » Ubuntu下使用阿里云Aliyun镜像安装Docker容器(CE版)

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址