docker 安装

Last updated on November 20, 2024 am

🧙 Questions

安装指定版本的docker

☄️ Ideas

卸载旧的版本
sudo yum remove -y docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
通过阿里云源安装docker

官方docker源
sudo yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum makecache fast
# centos8
# sudo yum makecache timer

查看可安装版本
sudo yum list docker-ce –showduplicates | sort -r
选择版本安装
sudo yum -y install docker-ce-${version} docker-ce-cli-${version} containerd.io
推荐19.03.9-3.el7

sudo yum -y install docker-ce-19.03.9-3.el7 docker-ce-cli-19.03.9-3.el7 containerd.io

# centos8
# sudo yum -y install docker-ce docker-ce-cli containerd.io
设置开机自启
sudo systemctl enable docker
配置阿里加速镜像仓库

如果可以直接访问外网,则不添加阿里加速镜像仓库

sudo mkdir -p /data/docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://3fe1zqfu.mirror.aliyuncs.com"],
  "data-root":"/data/docker"
}
EOF

查看状态: sudo systemctl status docker
停止服务: sudo systemctl stop docker
重启服务: sudo systemctl restart docker
查看配置信息: sudo docker info

sudo systemctl daemon-reload
sudo systemctl start docker
添加用户到docker用户组

添加完后,不需要每次都sudo才可以执行docker命令

sudo gpasswd -a ispong docker 
newgrp docker
sudo chmod a+rw /var/run/docker.sock
安装测试
docker run hello-world
配置clash网络代理(非必选)

如果有clash代理,可以配置

sudo mkdir /etc/systemd/system/docker.service.d
sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf

一定要配置NO_PROXY,否则[authz] rke-job-deployer ServiceAccount created successfully 无法创建

[Service]
Environment="HTTP_PROXY=http://172.16.215.83:7890"
Environment="HTTPS_PROXY=http://172.16.215.83:7890"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl show docker --property Environment
docker info | grep Proxy

docker 安装
https://ispong.isxcode.com/kubernetes/docker/docker 安装/
Author
ispong
Posted on
March 9, 2021
Licensed under