CentOS7下安装docker

本文详细介绍如何在CentOS7环境下安装Docker,并配置国内镜像加速,包括卸载旧版本、安装必要软件包、设置镜像源、安装Docker等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:

CentOS7

 

官方文档:

https://docs.docker.com/engine/install/centos/

 

步骤:

本次安装在root用户下操作,非root用户可根据实际情况在命令前添加sudo

1. 环境确认

查看系统内核为3.10及以上

# uname -r
3.10.0-957.21.3.el7.x86_64

查看系统版本,NAME="CentOS Linux"   VERSION="7 (Core)"

# 系统版本
[root@master ~]# cat /etc/os-release

2. 查看及卸载docker旧版本

 查看是否已安装docker

# docker --version
-bash: docker: command not found

command not fount:说明没有旧版本的docker。 

 如果已安装旧版本,执行以下命令卸载旧版本,否则不用执行卸载命令

# yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

3. 安装必要的包

# yum install -y yum-utils

 4.设置国内镜像仓库,例如:阿里云镜像仓库

# yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5.安装docker

# yum install -y docker-ce docker-ce-cli containerd.io

6.查看docker版本信息

简洁的版本信息
# docker --version

详细的版本信息
# docker version

7. 启动docker

# systemctl start docker

8. 测试docker hello world程序

# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
Status: Downloaded newer image for hello-world:latest

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

...

看到Hello from Docker成功运行

9.查看docker镜像

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              bf756fb1ae65        10 months ago       13.3kB

10.设置开机自启动

# systemctl enable docker

11.卸载docker(谨慎执行)

  如果要卸载docker,执行以下命令:

卸载依赖
# yum remove docker-ce docker-ce-cli containerd.io

移除资源目录
# rm -rf /var/lib/docker

 

 

完成! enjoy it!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值