ubuntu 安装 docker、docker-compose (阿里云源)

0x00 替换ubuntu源为阿里云源

文件:/etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb 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 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

0x01 安装docker

# 删除默认apt docker
sudo apt-get remove docker docker-engine docker.io

# 安装必备软件
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common curl

# 证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

# 写入软件源
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# 更新并获取想安装版本
sudo apt-get -y update
apt-cache madison docker-ce

```
 docker-ce | 5:18.09.0~3-0~ubuntu-bionic | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.3~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.2~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.1~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.0~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.03.1~ce~3-0~ubuntu | http://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
```
# 安装最新版本
sudo apt-get -y install docker-ce=18.06.1~ce~3-0~ubuntu

# 检查启动docker
systemctl status docker
sudo systemctl start docker

# 配置云加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://[阿里云分配的私有地址].mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

0x02 安装docker-compose

# 下载docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

# 增加执行权限
sudo chmod +x /usr/local/bin/docker-compose

# 查看版本,正常显示就安装成功
docker-compose --version

0x03 docker命令免输入 sudo 方法

由于docker属于操作系统级虚拟化技术,不同于VM、KVM方式;针对权限的管理特别重要,谨慎 --privileged启动

# 创建docker组
sudo groupadd docker

# 添加当前用户到docker组中
sudo usermod -aG docker $USER

#登出、重新登陆生效

#验证docker命令
docker run hello-world

 

你可能感兴趣的:(云计算架构师之路)