安装【Docker in CentOS7.x】

通过YUM工具安装

寻找合适的docker版本

1 查看Linux内核版本
  • 我是虚拟机装的Centos7,linux 3.10 内核,docker官方说至少3.8以上
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

安装docker-engine

1 yum包管理器
1.1 升级最新版本
[root@localhost ~]# yum update -y
# 升级过程可能要一段时间,略...
1.2 安装需要的软件包
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
1.3 设置yum源
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
2 docker安装
2.1 版本
# 查看所有可用版本
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
可安装的软件包
 * updates: mirrors.cn99.com
Loading mirror speeds from cached hostfile
 * extras: mirrors.cn99.com
docker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:20.10.6-3.el7                     
2.1 安装
# 安装选定可用版本,17.12.1可替换为上图的20.10.9
[root@localhost ~]# yum install -y docker-ce-17.12.1.ce
2.2 启动
# 启动docker
[root@localhost ~]# systemctl start docker
# 加入自启动服务
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
2.3 验证
[root@localhost ~]# docker version
Client:
 Version:	17.12.1-ce
 API version:	1.35
 Go version:	go1.9.4
 Git commit:	7390fc6
 Built:	Tue Feb 27 22:15:20 2018
 OS/Arch:	linux/amd64

Server:
 Engine:
  Version:	17.12.1-ce
  API version:	1.35 (minimum version 1.12)
  Go version:	go1.9.4
  Git commit:	7390fc6
  Built:	Tue Feb 27 22:17:54 2018
  OS/Arch:	linux/amd64
  Experimental:	false

通过官方脚本安装

安装截图

下载安装脚本

[root@docker01 src]# cd /usr/local/src/
# 下载脚本并保存为docker_install.sh文件
[root@docker01 src]# wget -q https://get.docker.com/ -O docker_install.sh
# 脚本会判断当前安装环境,自行选择安装
[root@docker01 src]# sh docker_install.sh
================================================================================

To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:

    dockerd-rootless-setuptool.sh install

Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.


To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/

WARNING: Access to the remote API on a privileged Docker daemon is equivalent
         to root access on the host. Refer to the 'Docker daemon attack surface'
         documentation for details: https://docs.docker.com/go/attack-surface/

================================================================================
# 查看docker服务状态
[root@docker01 src]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com
# 加入开机自启动
[root@docker01 src]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
# 启动服务
[root@docker01 src]# systemctl start docker
[root@docker01 src]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2022-05-28 21:47:49 CST; 6s ago
     Docs: https://docs.docker.com
 Main PID: 1393 (dockerd)
    Tasks: 7
   Memory: 34.7M
   CGroup: /system.slice/docker.service
           └─1393 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

528 21:47:47 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:47.783608279+08:00" level=info msg="ccRes...=grpc
5月 28 21:47:47 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:47.783615129+08:00" level=info msg="Clien...=grpc
528 21:47:47 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:47.824634346+08:00" level=info msg="Loadi...art."
528 21:47:48 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:48.729357337+08:00" level=info msg="Defau...ress"
528 21:47:48 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:48.864526334+08:00" level=info msg="Firew...ning"
528 21:47:48 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:48.972378763+08:00" level=info msg="Loadi...one."
528 21:47:49 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:48.999444294+08:00" level=info msg="Docke...10.16
5月 28 21:47:49 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:48.999562103+08:00" level=info msg="Daemo...tion"
5月 28 21:47:49 docker01.zangh dockerd[1393]: time="2022-05-28T21:47:49.043155492+08:00" level=info msg="API l...sock"
528 21:47:49 docker01.zangh systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
# 默认安装docker最新稳定版本,也可以通过修改docker_install.sh脚本制定安装版本
[root@docker01 src]# docker --version
Docker version 20.10.16, build aa7e414
[root@docker01 src]# docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值