安装一些系统工具
sudo yum install -y yum-utils
添加docker稳定的仓库(国内访问官方源可能失败,所以使用阿里云的仓库)
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker
sudo yum install docker-ce docker-ce-cli containerd.io
安装的时候会问需不需要继续的时候,输入y继续,最后等待即可。
另外,安装完成之后需要把docker模式拉取镜像源改一下,要不然也会访问官方镜像源,可能会无法访问:
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://m8y4mh9x.mirror.aliyuncs.com/"]
}
EOF
另外贴几个其他镜像源,可自行选择(如果都用不了了自行搜索其他可用的仓库即可):
网易: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
改完镜像源之后,重启docker
sudo systemctl restart docker
使用下列命令查看一下是否更改成功:
docker info
Client: Docker Engine - Community
Version: 26.1.4
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.14.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.27.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 26.1.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d2d58213f83a351ca8f528a95fbd145f5654e957
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 3.10.0-1160.119.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.715GiB
Name: XanaduInstanceHost
ID: acd5df4a-dab2-4bef-b72c-b9ddd50ef8d0
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://m8y4mh9x.mirror.aliyuncs.com/
Live Restore Enabled: false
在倒数第二行可以看到已经修改成功了,现在可以正常拉取镜像了。
注意:如果例子里的镜像用不了了,更换其他可用的源。