Centos 7 yum安装docker

centos 7安装docker环境

在此我们使用清华大学镜像源来进行安装
条件:能链接到外网
centos7自带docker仓库,但版本较老,更新速度也很慢,因此我们才需要配置为清华大学镜像仓库,当然根据自己的需求来设置也是可以的。

配置

清华大学开源软件镜像站

https://mirrors.tuna.tsinghua.edu.cn/

在列表中找到docker-ce,进入目录

https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/

可以看到docker-ce.repo
右键->复制链接地址
在Linux中的下载此文件到/etc/yum.repo.d目录下

wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

在网页上点击进入目录或者直接访问此仓库地址可以查看此仓库中是否有我们需要的版本

https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/

检查我们刚才下载的docker-ce.repo可以看到系在地址指向并非清华大学镜像仓库,因此我们需要替换为清华大学镜像地址(替换是为了速度下载速度快一些,随你喜欢)


# 替换文件中的地址为清华大学的地址
sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

懒得操作的可以复制以下内容

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/test

检查一下我们的仓库是否配置成功
可以见到我们配置的docker-ce已经有文件了

[root@localhost ~]# yum repolist
源标识                                                                                                                   源名称                                                                                                                                         状态
base/7/x86_64                                                                                                            CentOS-7 - Base                                                                                                                                10,097
docker-ce-stable/x86_64                                                                                                  Docker CE Stable - x86_64                                                                                                                          58
安装

运行命令
注意了:这里运行的是yum install docker-ce 不是yum install docker
使用运行yum install docker 使用的源extras(centos自带的),那我们上面的配置就没意义了

yum install docker-ce

如果遇到

You have enabled checking of packages via GPG keys. This is a good thing. 
However, you do not have any GPG public keys installed. You need to download
the keys for packages you wish to install and install them.
You can do that by running the command:
    rpm --import public.gpg.key

运行下面

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

配置加速器

配置加速器是很有必要的

 mkdir -p /etc/docker
vim /etc/docker/daemon.json
##daemon.json 内容如下
{
  "registry-mirrors": ["你自己选的加速器地址可以是"]
} 
##加速器地址:
		腾讯:https://mirror.ccs.tencentyun.com
		中国科技大学:https://docker.mirrors.ustc.edu.cn/
		阿里的在在你注册后会给你生成一个,根据提示操作就可以

注意:添加以后在启动,若果事先已经启动了,添加以后需要重启docker才能生效

验证加速器是否生效

运行

docker info

检查 Registry Mirrors:是否为你自己配置的加速器地址

docker daemon.json常用配置

docker安装后默认没有daemon.json这个配置文件,需要进行手动创建,docker不管是在哪个平台以何种方式启动, 默认都会来这里读取配置,使用户可以统一管理不同系统下的 docker daemon 配置。
如果在daemon.json文件中进行配置,需要docker版本高于1.12,配置文件的默认径为:/etc/docker/daemon.json
该文件作为 Docker Engine 的配置管理文件, 里面几乎涵盖了所有 docker 命令行启动可以配置的参数。

  • 文档

https://docs.docker.com/engine/reference/commandline/dockerd/#daemon

这里面的配置很多,别担心,常用的配置不多,其他保持默认即可,需要修改了在来添加
以下内容来自于jianweixs博主

https://www.jianshu.com/p/c7c7dc24b9e3

{
    "authorization-plugins": [],
    "data-root": "", 
     #Docker运行时使用的根路径,根路径下的内容稍后介绍,默认/var/lib/docker
    "dns": [],  
     #设定容器DNS的地址,在容器的 /etc/resolv.conf文件中可查看
    "dns-opts": [],
     #容器 /etc/resolv.conf 文件,其他设置
    "dns-search": [],
     #设定容器的搜索域,当设定搜索域为 .example.com 时,在搜索一个名为 host 的 主机时,DNS不仅搜索host,还会搜索host.example.com。注意:如果不设置,Docker 会默认用主机上的 /etc/resolv.conf来配置容器。
    "exec-opts": [],
    "exec-root": "",
    "experimental": false,
    "features": {},
    "storage-driver": "",
    "storage-opts": [],
    "labels": [],
     #docker主机的标签,很实用的功能,例如定义:–label nodeName=host-121
    "live-restore": true,
    "log-driver": "",
    "log-opts": {},
    "mtu": 0,
    "pidfile": "",
     #Docker守护进程的PID文件
    "cluster-store": "",
    "cluster-store-opts": {},
    "cluster-advertise": "",
    "max-concurrent-downloads": 3,
    "max-concurrent-uploads": 5,
    "default-shm-size": "64M",
    "shutdown-timeout": 15,
    "debug": true, 
     #启用debug的模式,启用后,可以看到很多的启动信息。默认false
    "hosts": [],
    #设置容器hosts
    "log-level": "",
    "tls": true,  
     #默认 false, 启动TLS认证开关
    "tlscacert": "", 
     #默认 ~/.docker/ca.pem,通过CA认证过的的certificate文件路径
    "tlscert": "", 
     #默认 ~/.docker/cert.pem ,TLS的certificate文件路径
    "tlskey": "",
     #默认~/.docker/key.pem,TLS的key文件路径
    "tlsverify": true,
     #默认false,使用TLS并做后台进程与客户端通讯的验证
    "tls": true,
    "tlsverify": true,
    "tlscacert": "",
    "tlscert": "",
    "tlskey": "",
    "swarm-default-advertise-addr": "",
    "api-cors-header": "",
    "selinux-enabled": false, 
     #默认 false,启用selinux支持
    "userns-remap": "",
    "group": "",
     #Unix套接字的属组,仅指/var/run/docker.sock
    "cgroup-parent": "",
    "default-ulimits": {
        "nofile": {
            "Name": "nofile",
            "Hard": 64000,
            "Soft": 64000
        }
    },
    "init": false,
    "init-path": "/usr/libexec/docker-init",
    "ipv6": false,
    "iptables": false,
    "ip-forward": false,
    #默认true, 启用 net.ipv4.ip_forward ,进入容器后使用sysctl -a|grepnet.ipv4.ip_forward查看
    "ip-masq": false,
    "userland-proxy": false,
    "userland-proxy-path": "/usr/libexec/docker-proxy",
    "ip": "0.0.0.0",
    "bridge": "",
    "bip": "",
    "fixed-cidr": "",
    "fixed-cidr-v6": "",
    "default-gateway": "",
    "default-gateway-v6": "",
    "icc": false,
    "raw-logs": false,
    "allow-nondistributable-artifacts": [],
    "registry-mirrors": [],
     #镜像加速的地址,增加后在 docker info中可查看。
    "seccomp-profile": "",
    "insecure-registries": [],
     #配置docker的私库地址
    "no-new-privileges": false,
    "default-runtime": "runc",
    "oom-score-adjust": -500,
    "node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"],
    "runtimes": {
        "cc-runtime": {
            "path": "/usr/bin/cc-runtime"
        },
        "custom": {
            "path": "/usr/local/bin/my-runc-replacement",
            "runtimeArgs": [
                "--debug"
            ]
        }
    },
    "default-address-pools":[{"base":"172.80.0.0/16","size":24},
    {"base":"172.90.0.0/16","size":24}]
}
  • 常用配置项

  • insecure-registries 设置私有仓库时必须在这指定
  • registry-mirrors 镜像加速
  • data-root 默认路径/var/lib/docker在生产环境使用时可能需要指定,这里面存了你docker拉取的镜像、运行时的容器等,当然你的存储空间足够,你也可以不指定
  • storage-drive

docker常用命令

略,先到这,以后再补吧

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值