一键脚本安装:
$ sudo wget -qO- https://get.docker.com/ | bash
$ # 如果上面的不行,执行下面两句
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
$ # 安装成功执行下面语句,如果有类似回显,说明安装成功
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
ubuntu系统(均为64位操作系统)版本要求:
Bionic 18.04 (LTS)
Artful 17.10
Xenial 16.04 (LTS)
Trusty 14.04 (LTS)
更改系统软件源为国内阿里云源
1)、备份系统内置sources.list文件
sudo mv /etc/apt/sources.list /etc/apt/sources.list.back
2)、使用vim增加新的sources.list文件
sudo vim /etc/apt/sources.list
按a、i、o三者任意一个按键进入编辑模式插入以下代码
deb-src http://archive.ubuntu.com/ubuntu bionic main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ bionic universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe
deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates 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 #Added by software-properties
deb http://archive.canonical.com/ubuntu bionic partner
deb-src http://archive.canonical.com/ubuntu bionic partner
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ bionic-security universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-security multiverse
按esc键(进入命令模式)
:wq (保存并退出)
3)更新系统apt包索引
sudo apt-get update
安装docker
1、删除老版本docker
sudo apt-get remove docker docker-engine docker.io
2、删除老版本docker数据目录
sudo rm -rf /var/lib/docker/
3、安装https相关工具,让安装包允许apt通过HTTPS使用软件仓库
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
4、添加Docker的官方GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
5、配置docker稳定版仓库地址
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
6、再次更新apt包索引
sudo apt-get update
7、安装docker-ce
sudo apt-get install -y docker-ce
8、验证docker是否安装成功
sudo docker run hello-world
以下操作为非root
用户操作,root用户不用操作
9、将当前帐号添加到docker用户组
sudo usermod -aG docker $USER
10、重启docker服务
sudo service docker restart
11、切换group
newgrp - docker
12、脚本一键安装方式
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
安装docker-compose
1.安装docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
2.给docker-compose添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
3.检验
docker-compose --version