美文网首页
[K8S系列二]Centos安装docker

[K8S系列二]Centos安装docker

作者: 925781609 | 来源:发表于2022-03-19 16:25 被阅读0次

docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 LinuxWindows操作系统的机器上,也可以实现虚拟化

1 安装过程

# 01 更新并安装依赖
    yum -y update
    yum install -y conntrack ipvsadm ipset jq sysstat curl iptables libseccomp
# 02 卸载低版本的docker(如果存在的话)
    sudo yum remove docker docker latest docker-latest-logrotate \
    docker-logrotate docker-engine docker-client docker-client-latest docker-common
# 03 安装必要依赖
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 04 添加软件源信息
    sudo yum-config-manager \
    --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    yum list | grep docker-ce
# 05 更新yum缓存
    sudo yum makecache fast
# 06 安装docker,可以指定安装docker版本
    sudo yum install -y docker-ce-18.09.0 docker-ce-cli-18.09.0 containerd.io 
# 07 启动docker并设置开机启动
    sudo systemctl start docker && sudo systemctl enable docker
# 08 测试docker安装是否成功
    sudo docker run hello-world

如果打印如下信息则提示安装成功

Hello from Docker!
This message shows that your installation appears to be working correctly.

2 可能存在的问题

2.1 拉取不到镜像
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https:
//auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: request can
celed (Client.Timeout exceeded while awaiting headers).```

这个是因为默认使用国外的镜像源,拉取镜像会有问题,需要配置docker中国镜像

创建或修改 /etc/docker/daemon.json 文件,修改为如下内容:

{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://registry.cn-hangzhou.aliyuncs.com"
  ]
}

修改之后需要重启一下docker

systemctl restart docker.service

相关文章

网友评论

      本文标题:[K8S系列二]Centos安装docker

      本文链接:https://www.haomeiwen.com/subject/yfagdrtx.html