安装docker
centos7.2下安装docker1.13.1或者安装17.03.2
关闭selinux
setenforce 0 sed -ri 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
开启防火墙:
yum install firewalld -y systemctl start firewalld && systemctl enable firewalld && systemctl stop iptables && systemctl disable iptables #开启相应的端口 firewall-cmd --zone=public --add-port=8000-10200/tcp --permanent firewall-cmd --zone=public --add-port=5000/tcp --permanent firewall-cmd --zone=public --add-port=2375/tcp --permanent firewall-cmd --reload
设置IPV4转发
vim /etc/sysctl.conf #开启转发 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 #端口范围 net.ipv4.ip_local_port_range = 2048 65535 #监听队列长度 net.core.somaxconn = 4096 #网络接口接收数据包的速率比内核处理包的速率快时,允许送到队列的数据包的最大数目 net.core.netdev_max_backlog = 65000 #SYN_RECV状态队列长度 net.ipv4.tcp_max_syn_backlog = 8196 执行如下命令生效: sysctl -p
系统资源修改:
vim /etc/security/limits.d/10-nproc.conf * soft nproc 20480 * hard nproc 20480 root soft nproc unlimited root hard nproc unlimited * soft nofile 1048576 * hard nofile 1048576
一 yum安装docker, 默认的版本是1.13.1,比以往的要高,以前都是1.12.3或者1.12.6
yum install docker -y && systemctl start docker && systemctl stop docker
使用devicemapper存储驱动程序配置Docker
https://docs.docker.com/storage/storagedriver/device-mapper-driver/#configure-docker-with-the-devicemapper-storage-driver
修改docker配置
a. vim /etc/docker/daemon.json { "storage-driver": "devicemapper", "storage-opts": [ "dm.thinpooldev=/dev/mapper/docker-thinpool", "dm.use_deferred_removal=true", "dm.use_deferred_deletion=true" ], "registry-mirrors": [ "http://f2d6cb40.m.daocloud.io", "https://registry.docker-cn.com", "http://ef017c13.m.daocloud.io", "http://74ecfe5d.m.daocloud.io", "http://e1c83636.m.daocloud.io" ], "insecure-registries": [ "ip:5000", "ip:5000" ], "live-restore": true, "graph": "/opt/docker", "hosts": [ "unix:///var/run/docker.sock", "tcp://0.0.0.0:2375" ] } b.vim /etc/sysconfig/docker-storage-setup #STORAGE_DRIVER=overlay2 CONTAINER_THINPOOL=docker-pool c.vim /etc/sysconfig/docker-storage DOCKER_STORAGE_OPTIONS=
启动docker:
systemctl daemon-reload && systemctl restart docker && systemctl enable docker
二 通过阿里云的方式安装docker-ce-17.03.2.ce
# step 0: 删除系统里面的docker组件 yum remove docker docker-common container-selinux docker-selinux docker-engine docker-engine-selinux # step 1: 安装必要的一些系统工具 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 # Step 2: 添加软件源信息 sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # Step 3: 更新并安装 Docker-CE sudo yum makecache fast yum install -y --setopt=obsoletes=0 docker-ce-17.03.2.ce docker-ce-selinux-17.03.2.ce # Step 4: 开启Docker服务 sudo systemctl start docker
使用devicemapper存储驱动程序配置Docker
https://docs.docker.com/storage/storagedriver/device-mapper-driver/#configure-docker-with-the-devicemapper-storage-driver
修改docker配置
vim /etc/docker/daemon.json
{ "storage-driver": "devicemapper", "storage-opts": [ "dm.thinpooldev=/dev/mapper/docker-thinpool", "dm.use_deferred_removal=true", "dm.use_deferred_deletion=true" ], "registry-mirrors": [ "http://f2d6cb40.m.daocloud.io", "http://ef017c13.m.daocloud.io", "http://74ecfe5d.m.daocloud.io", "http://e1c83636.m.daocloud.io" ], "insecure-registries": [ "ip:5000", "harbor.xxx.com" ], "live-restore": true, "graph": "/opt/docker", "hosts": [ "unix:///var/run/docker.sock", "tcp://0.0.0.0:2375" ], "selinux-enabled": false, "userland-proxy": false, "exec-opts": [ "native.cgroupdriver=systemd" ] }
启动docker:
systemctl daemon-reload && systemctl restart docker && systemctl enable docker