CentOS7.x 安装Docker

本文详细介绍了在CentOS7系统上安装、配置DockerCE,包括从包管理器安装、验证、启动服务、镜像加速等步骤,以及停止和重启Docker的方法。
摘要由CSDN通过智能技术生成
【安装参考】
https://docs.docker.com/engine/install/centos/
https://docs.docker.com/engine/install/centos/#install-from-a-package
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-20.10.24-3.el7.x86_64.rpm

【卸载】
yum remove docker docker-client docker-client-latest docker-common docker-lastest docker-lastest-logrotate docker-logrotate docker-selinux docker-engin-selinux docker-engine -y
【安装】

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

查看可用版本:
yum list docker-ce --showduplicates | sort -r


安装指定版本命令:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin

<VERSION_STRING>示例:docker-ce-3:20.10.24-3.el7, 3:20.10.24-3.el7,实测有效名称为:docker-ce-20.10.24-3.el7,不要带上前面的“3:”

命令格式:
sudo yum install docker-ce-3:20.10.24-3.el7 docker-ce-cli-3:20.10.24-3.el7 containerd.io docker-buildx-plugin docker-compose-plugin -y

# CentOS 7环境实际有效命令:
sudo yum install docker-ce-20.10.24-3.el7 docker-ce-cli-20.10.24-3.el7 containerd.io  docker-compose-plugin -y


注意:因为docker-buildx-plugin 插件存在版本冲突,不知道兼容版本可以不安装


查看安装组件:yum list installed | grep docker


启动服务前检查

# docker version
Client: Docker Engine - Community
 Version:           20.10.24
 API version:       1.41
 Go version:        go1.19.7
 Git commit:        297e128
 Built:             Tue Apr  4 18:22:57 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?


启动:sudo systemctl start docker

启动后查看
# sudo systemctl start docker
# docker version
Client: Docker Engine - Community
 Version:           20.10.24
 API version:       1.41
 Go version:        go1.19.7
 Git commit:        297e128
 Built:             Tue Apr  4 18:22:57 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.24
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.19.7
  Git commit:       5d6db84
  Built:            Tue Apr  4 18:21:02 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@hecs-342376 cli-plugins]# 


【验证安装成果】

sudo docker run hello-world

# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:dcba6daec718f547568c562956fa47e1b03673dd010fe6ee58ca806767031d1c
Status: Downloaded newer image for hello-world:latest

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

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

【停止服务】
# sudo systemctl stop docker
【镜像加速配置】

方式1:手动配置
vim /etc/docker/daemon.json

格式:
{
    "registry-mirrors": [
        "加速地址"
    ],
    "insecure-registries": []
}
示例:
{
 "registry-mirrors":[
     "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}


科大镜像:https://docker.mirrors.ustc.edu.cn/
网易:https://hub-mirror.c.163.com/
阿里云:https://<你的ID>.mirror.aliyuncs.com

方式2:脚本命令配置

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

【重启Docker】
sudo systemctl daemon-reload 
sudo systemctl restart docker
docker version
systemctl enable docker
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值