Docker 安装及配置
1 安装
1.1 debain
使用脚本自动安装
1
2curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun手动安装
更新软件包索引,并且安装必要的依赖软件,来添加一个新的 HTTPS 软件源
1
2sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common使用下面的
curl
导入源仓库的GPG key
:1
2
3
4
5官方:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Aliyun
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -安装 Docker 最新版本
1
2sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
启动
Docker
1
2sudo systemctl enable docker
sudo systemctl start docker建立
docker
用户组默认情况下,
docker
命令会使用Unix socket
与Docker
引擎通讯。而只有root
用户和docker
组的用户才可以访问Docker
引擎的Unix socket
。出于安全考虑,一般Linux
系统上不会直接使用root
用户。因此,更好地做法是将需要使用docker
的用户加入docker
用户组。1
2
3
4
5
6建立 docker 组:
sudo groupadd docker
将当前用户加入 docker 组:
sudo usermod -aG docker $USER
退出当前终端并重新登录docker
镜像1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20网易:http://hub-mirror.c.163.com
中科大镜像地址:http://mirrors.ustc.edu.cn/
中科大github地址:https://github.com/ustclug/mirrorrequest
Azure中国镜像地址:http://mirror.azure.cn/
Azure中国github地址:https://github.com/Azure/container-service-for-azure-china
DockerHub镜像仓库: https://hub.docker.com/
阿里云镜像仓库: https://cr.console.aliyun.com
google镜像仓库: https://console.cloud.google.com/gcr/images/google-containers/GLOBAL (如果你本地可以翻墙的话是可以连上去的 )
coreos镜像仓库: https://quay.io/repository/
RedHat镜像仓库: https://access.redhat.com/containers
配置:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://cr.console.aliyun.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
1.2 Centos
使用脚本自动安装
1
2curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun手动安装
安装依赖
1
sudo yum install -y yum-utils # openEuler 自带 dnf 管理器,可直接管理 yum 源
配置docker仓库
1
2
3
4
5官方:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Aliyun:
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo下载安装
1
2sudo yum makecache fast # 更新索引
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin(openEuler)更新索引时,可能会报错404,可按如下方法解决
1
2
3
4
5
6
7cd /etc/yum.repos.d/
# ls -lhrt
# -rw-r--r--. 1 root root 2.7K Dec 9 20:33 openEuler.repo.bak
# -rw-r--r--. 1 root root 3.0K Dec 9 20:37 openEuler.repo
# -rw-r--r--. 1 root root 2.0K Feb 3 16:45 docker-ce.repo
编辑 docker-ce.repo,将 $releasever 替换为 8,即CentOS8,使得能够在阿里云的centos仓库中找到对应的工具