centos7安装docker
一。修改yum源为阿里云的
1. 进入yum目录
[root@localhost yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo [root@localhost yum.repos.d]#
2. 备份
[root@localhost yum.repos.d]# mkdir back [root@localhost yum.repos.d]# mv ./*.repo back/ [root@localhost yum.repos.d]# ls back [root@localhost yum.repos.d]#
3. 下载
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo --2018-12-29 11:35:16-- http://mirrors.aliyun.com/repo/Centos-7.repo 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 124.227.25.157, 124.227.25.149, 124.227.25.154, ... 正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|124.227.25.157|:80... 已连接。
...
[root@localhost yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo --2018-12-29 11:36:38-- https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 124.227.25.152, 124.227.25.151, 124.227.25.156, ... ...
[root@localhost yum.repos.d]# ls back Centos-7.repo docker-ce.repo [root@localhost yum.repos.d]#
4. 更新源标识
[root@localhost yum.repos.d]# yum repolist 已加载插件:fastestmirror, langpacks base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 extras | 3.4 kB 00:00:00 ...
二。安装
1. 在线标准安装
[root@localhost yum.repos.d]# yum install docker-ce 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile ...
2. 开机启动docker Daemon进程
[root@localhost yum.repos.d]# systemctl start docker.service [root@localhost yum.repos.d]# systemctl enable docker.service Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@localhost yum.repos.d]#
3. 查看版本
[root@localhost ~]# docker version Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:48:22 2018 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:19:08 2018 OS/Arch: linux/amd64 Experimental: false [root@localhost ~]#
4. 查看docker信息
[root@localhost ~]# docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 18.09.0 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39 runc version: 4fc53a81fb7c994640722ac585fa9ca548971871 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-693.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 976.3MiB Name: localhost.localdomain ID: PFMV:N577:HBSK:XKEO:M6NY:QTAM:PILH:7EXQ:SGKA:AXNX:LDUW:JL2X Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false Product License: Community Engine
5. 开启阿里云镜像加速
网易镜像:https://c.163.com/hub
在阿里云获取加速地址,加入到 /etc/docker/daemon.json 文件中
{ "registry-mirrors": ["https://registry.docker-cn.com"] }
三。授予普通用户使用的权限
1. 查看是否有 docker 组,没有则创建
[root@localhost ~]# cat /etc/group | grep "docker" docker:x:994: [root@localhost ~]#
2. 把用户 gh 加入到docker组中
[root@localhost ~]# usermod -G docker gh [root@localhost ~]#
3. 重新登陆即可
[gh@localhost ~]$ docker version Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:48:22 2018 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:19:08 2018 OS/Arch: linux/amd64 Experimental: false [gh@localhost ~]$
四。配置文件
1. 默认配置文件: /etc/docker/daemon.json
2. 初始化配置文件: /usr/lib/systemd/system/docker.service
3. 容器配置文件: /etc/containerd/config.toml
官网文档 https://docs.docker.com/config/daemon/#force-a-stack-trace-to-be-logged