# docker 环境配置
> ubuntu 18.04.1  
> 与官网具体讲解不同,本文略去了大量细节介绍,具体看官方教程  
> [参考链接](https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository)

## 安装普通 docker
### 1. 移除可能安装的旧版本`docker`相关程序
> 这一步可以不需要,如果新机器的话
```shell
sudo apt-get remove docker docker-engine docker.io containerd runc
```
### 2. 更新基础依赖
更新`apt`仓库
```shell
sudo apt-get update
```
安装基础依赖
```shell
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
```
### 3. 设置`GPG key`
这段功能没细看
```shell
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
```

### 4. 使用`docker`仓库
这段代码也没细看,官网表示跟着输入就行
```shell
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```

### 5. 更新依赖
```shell
sudo apt-get update
```
> [!tip] 如果执行`update`命令报错提示`GPG`什么的,可能是下面原因  
> Your default umask may be incorrectly configured,   
> preventing detection of the repository public key file.   
> Try granting read permission for the Docker public key file before updating the package index:

可执行的错误修改代码
```shell
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update
```

### 6. 安装docker
<!-- tabs:start -->
#### **稳定版`latest`**
##### 1.安装
```shell
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```
##### 2. 测试
> 感觉没什么必要
```shell
sudo docker run hello-world
```
#### **指定版本**
##### 1. 列出指定版本
```shell
# List the available versions:
apt-cache madison docker-ce | awk '{ print $3 }'
```
可能返回的结果
```
5:20.10.16~3-0~ubuntu-jammy
5:20.10.15~3-0~ubuntu-jammy
5:20.10.14~3-0~ubuntu-jammy
5:20.10.13~3-0~ubuntu-jammy
```
##### 2. 选择安装指定版本
```shell
VERSION_STRING=5:20.10.13~3-0~ubuntu-jammy
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
```
##### 3. 测试...
<!-- tabs:end -->