ubuntu20.04系统中安装最新版docker、docker-compose流程步骤
我是在阿里云ecs上的最新ubuntu20.4系统,后面所以教程架构都会基于该版本进行
进入步骤:
0.开始先更新一下源
[email protected]:~# apt update
1.允许apt通过https使用repository安装软件包
apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
执行命令 (太长了我就...省略了)
[email protected]:~# sudo apt-get install \
> apt-transport-https \
> ca-certificates \
> curl \
> gnupg-agent \
> software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20210119~20.04.2).
curl is already the newest version (7.68.0-1ubuntu2.8).
The following package was automatically installed and is no longer required:
libsasl2-modules
Use 'sudo apt autoremove' to remove it.
...
Do you want to continue? [Y/n] y
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 libpolkit-gobject-1-0 amd64 0.105-26ubuntu1.3 [39.2 kB]
...
Fetched 2,400 kB in 2s (1,410 kB/s)
Preconfiguring packages ...
(Reading database ... 120915 files and directories currently installed.)
Preparing to unpack .../00-libpolkit-gobject-1-0_0.105-26ubuntu1.3_amd64.deb ...
...
Setting up unattended-upgrades (2.3ubuntu0.1) ...
Creating config file /etc/apt/apt.conf.d/50unattended-upgrades with new version
...
Processing triggers for dbus (1.12.16-2ubuntu2.1) ...
2.添加Docker GPG key 及 验证key (国内阿里云版)
[email protected]:~# curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
OK
[email protected]:~# 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) <[email protected]>
sub rsa4096 2017-02-22 [S]
3.添加repository(国内阿里云版)
add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
执行命令
[email protected]:~# sudo add-apt-repository \
> "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports InRelease
Hit:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Get:5 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease [57.7 kB]
Get:6 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal/stable amd64 Packages [13.5 kB]
Fetched 71.2 kB in 1s (119 kB/s)
Reading package lists... Done
4.更新源 (...省略)
[email protected]:~# apt-get update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal InRelease
Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-backports InRelease
Hit:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal-security InRelease
Hit:5 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease
Reading package lists... Done
5.安装最新版docker (...表示省略)
[email protected]:~# apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libsasl2-modules
Use 'apt autoremove' to remove it.
...
Do you want to continue? [Y/n] y
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
...
Processing triggers for systemd (245.4-4ubuntu3.15) ...
6.安装好 看一下docker版本
[email protected]:~# docker version
Client: Docker Engine - Community
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:33 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:42 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
7.开机启动设置
#看一下docker开机启动状态
[email protected]:~# systemctl list-unit-files | grep docker
docker.service enabled enabled
docker.socket enabled enabled
#没有的话就要设置,开机启动命令
systemctl enable docker
8.安装docker-compose
#github源超时 大环境是这样 没办法只能换源
curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#执行命令
[email protected]:~# curl -L "https://get.daocloud.io/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 423 100 423 0 0 165 0 0:00:02 0:00:02 --:--:-- 165
100 23.5M 100 23.5M 0 0 8177k 0 0:00:02 0:00:02 --:--:-- 120M
[email protected]:~# chmod +x /usr/local/bin/docker-compose
[email protected]:~# docker-compose --version
Docker Compose version v2.2.2
9.配置阿里云镜像仓库加速
#在/etc/docker/目录下创建daemon.json文件 输入你的加速地址 注意是你的 老铁
[email protected]:~# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://ft5scn333r.mirror.aliyuncs.com"]
}
#加载信息 重启docker
[email protected]:~# systemctl daemon-reload
[email protected]:~# systemctl restart docker
#看一下是否生效了 ...代表省略
[email protected]:~# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
scan: Docker Scan (Docker Inc., v0.12.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.12
Storage Driver: overlay2
...
Registry Mirrors:
https://ft5scn3r.mirror.aliyuncs.com/
Live Restore Enabled: false
相关文章