官方文档地址:https://docs.docker.com/engine/install/centos/
安装命令补全
# yum install bash-comple*
# source /usr/share/bash-completion/bash_completion
rpm安装
官方rpm安装包下载地址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
阿里云rpm包下载地址:https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/
安装过程
# curl -o /usr/local/src/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
# yum install -y /usr/local/src/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
启动并验证
# systemctl start docker # docker info|grep -i "server version" Server Version: 18.03.1-ce
二进制安装
二进制包下载地址:
- 官方:https://download.docker.com/linux/static/stable/x86_64/
- 阿里云:https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/
安装过程
1、下载安装包并解压
# wget https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-18.03.1-ce.tgz # tar -zvxf docker-18.03.1-ce.tgz # cp docker/* /usr/bin/
2、编写unit文件
# vim /etc/systemd/system/docker.service
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID LimitNOFILE=infinity LimitNPROC=infinity TimeoutStartSec=0 Delegate=yes KillMode=process Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
添加权限
# chmod +x /etc/systemd/system/docker.service
重载配置并启动docker
# systemctl daemon-reload
# systemctl start docker
验证
# docker info|grep -i "server version" Server Version: 18.03.1-ce
使用aliyun的yum源安装
配置yum源
# rm -rf /etc/yum.repos.d/* # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo # wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker
移除旧版本
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
安装yum工具类
# yum install -y yum-utils device-mapper-persistent lvm2
如果安装的是新版的docker,可以先列出安装的docker组件再卸载
[root@docker02 ~]# yum list installed|grep docker containerd.io.x86_64 1.4.6-3.1.el7 @docker-ce-stable docker-ce-cli.x86_64 1:20.10.7-3.el7 @docker-ce-stable docker-scan-plugin.x86_64 0.8.0-3.el7 @docker-ce-stable [root@docker02 ~]# yum remove docker-ce-cli.x86_64 containerd.io.x86_64 docker-scan-plugin.x86_64 -y
安装指定版本docker
[root@docker02 ~]# yum install docker-ce-18.09.9 docker-ce-cli-18.09.9 containerd.io
启动docker
# systemctl start docker
docker info信息解读
[root@localhost ~]# docker info Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Build with BuildKit (Docker Inc., v0.5.1-docker) scan: Docker Scan (Docker Inc., v0.8.0) Server: Containers: 0 # 当前主机运行的容器总数 Running: 0 # 当前运行中的容器 Paused: 0 # 当前暂停的容器 Stopped: 0 # 当前已经停止的容器 Images: 0 # 当前服务器的镜像数 Server Version: 18.09.9 # 服务端的docker版本 Storage Driver: overlay2 # 当前docker服务使用的存储引擎 Backing Filesystem: xfs # 当前服务器的文件系统 Supports d_type: true # 是否支持d_type,分层 Native Overlay Diff: true # 是否支持差异化数据存储 userxattr: false Logging Driver: json-file # 日志的存储格式 Cgroup Driver: cgroupfs # cgroups的类型 Cgroup Version: 1 Plugins: Volume: local # 卷存储 Network: bridge host ipvlan macvlan null overlay # overlay跨主机通信 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog # 日志类型 Swarm: inactive # 是否支持swarm Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux # 运行时 Default Runtime: runc # 默认运行时 Init Binary: docker-init # 初始化容器的进程,即pid为1的进程 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7 init version: de40ad0 # init版本 Security Options: seccomp # 操作审计,https://docs.docker.com/engine/security/seccomp Profile: default # 默认的配置文件 Kernel Version: 3.10.0-862.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 1.779GiB Name: localhost.localdomain ID: G55U:HZQF:LKAF:I42F:3VZS:PBEV:YQHU:OXRZ:PMIB:LK5Q:SDVX:LJJL Docker Root Dir: /var/lib/docker # 宿主机数据保存目录 Debug Mode: false Registry: https://index.docker.io/v1/ # 镜像仓库 Labels: Experimental: false # 是否是测试版 Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false #是否开启活动重启,即重启docker-daemon不关闭容器