Docker学习(一)——docker的安装(Ubuntu18.04系统)
1. 官网地址(官网的安装方式总是最新的)
官网地址:https://docs.docker.com/get-docker/
2. 环境准备
64位的主机,Ubuntu支持版本如下图
3. 在linux终端输入以下指令
3.1 更新apt包目录
$ sudo apt-get update #更新包目录
$ sudo apt-get install \ #运行apt使用https从repository获取docker包
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
3.2 添加dockers官方 GPG 密钥
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
3.3 验证密钥成功添加
$ 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]
3.4 设置稳定的仓库源
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
3.5 安装docker引擎
#安装最新的版本
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
#安装指定版本
$ apt-cache madison docker-ce
#输出:
docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
...
$ sudo apt-get install docker-ce=18.06.1~ce~3-0~ubuntu docker-ce-cli=18.06.1~ce~3-0~ubuntu containerd.io
3.6 通过经典的hello world验证是否成功安装
$ sudo docker run hello-world #pull并运行hello world 镜像
#输出
hello from Docker!
...
4. 网络存在问题上述指令无法成功安装时,更换国内镜像源
4.1 通过vim打开/etc/apt/sources.list
sudo vim /etc/apt/sources.list
#有需要的话可以先备份该文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list #将文件复制一份
4.2 修改源
输入i进入编辑模式,将下方内容复制粘贴进入source.list文件即可
#阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
按Esc退出编辑,输入 :wq 完成写入退出
$ sudo apt-get update #更新目录
4.3 常用国内镜像站网址
清华源 https://mirrors.tuna.tsinghua.edu.cn
阿里云 https://developer.aliyun.com/mirror/
搜狐 http://mirrors.sohu.com
网易 http://mirrors.163.com
华科大 http://mirror.hust.edu.cn
中科大 https://mirrors.ustc.edu.cn