Docker环境初始化
更新yum repo为阿里云源
yum install -y curl
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bk
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
升级内核(至4.12.5)后重启
uname -sr
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
yum --enablerepo=elrepo-kernel install -y kernel-ml
awk -F\' '$1=="menuentry " {print i++ " @ " $2}' /etc/grub2.cfg
grub2-set-default 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
reboot
安装相关软件,设置docker.repo
yum install -y yum-utils device-mapper-persistent-data libcgroup libtool-ltdl libseccomp lvm2 libdevmapper*
cat <<EOF >> /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl -p
cat <<EOF > /etc/yum.repos.d/docker.repo
[docker-main]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
安装docker
- 1.12.1
- https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-1.12.1-1.el7.centos.x86_64.rpm
- https://yum.dockerproject.org/repo/main/centos/7/Packages/docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
yum install -y docker-engine-selinux-1.12.1-1.el7.centos.noarch docker-engine-1.12.1-1.el7.centos.x86_64
- 1.12.6
yum list docker.x86_64 --showduplicates |sort -r
yum install -y docker-1.12.6-16.el7.centos.x86_64
- 1.13.1
yum list docker-latest.x86_64 --showduplicates |sort -r
- docker-ce 17.05
yum list docker-ce.x86_64 --showduplicates |sort -r
yum list docker-engine.x86_64 --showduplicates |sort -r
yum list docker-engine-selinux.noarch --showduplicates |sort -r
yum install -y docker-engine-selinux-17.05.0.ce-1.el7.centos.noarch docker-engine-17.05.0.ce-1.el7.centos.x86_64
配置/etc/sysconfig/docker及docker.service, 启动docker
- /etc/sysconfig/docker
cat <<EOF >/etc/sysconfig/docker
OPTIONS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --log-driver=json-file --storage-driver=overlay --exec-opt native.cgroupdriver=cgroupfs --graph=/localdisk/docker/graph --insecure-registry=gcr.io --insecure-registry=quay.io --insecure-registry=registry.cn-hangzhou.aliyuncs.com --insecure-registry=192.168.56.101 --insecure-registry=192.168.56.101:5000 --registry-mirror=http://138f94c6.m.daocloud.io --registry-mirror=https://olzwzeg2.mirror.aliyuncs.com --registry-mirror https://ip2y4bft.mirror.aliyuncs.com --label com.domain.env=test --label com.domain.bizcluster=devops --label com.domain.publicnetwork=false"
EOF
- /usr/lib/systemd/system/docker.service
cat <<EOF >/usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/docker
#ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 $OPTIONS
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock $OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
#TasksMax=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
- 启动docker daemon
systemctl daemon-reload
systemctl status docker
systemctl restart docker
systemctl status docker -l
docker version
docker info
添加用户test
useradd -r -m -s /bin/bash test
echo test:test |chpasswd
groupadd sudo
usermod -aG sudo test
echo "test ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
visudo -cf /etc/sudoers
sudo groupadd docker
sudo gpasswd -a test docker #usermod -aG docker devops
overlayfs存储方式
devicemapper存储方式
生产环境手动配置direct-lvm步骤
- https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/#configure-direct-lvm-mode-for-production
- https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/#configure-direct-lvm-mode-manually
- https://github.com/moby/moby/issues/21701
- https://www.tecmint.com/setup-thin-provisioning-volumes-in-lvm/
- https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-disk-storage-lvm.html => LVM Commands
/etc/lvm/profile/docker-thinpool.profile
cat <<EOF >/etc/lvm/profile/docker-thinpool.profile
activation {
thin_pool_autoextend_threshold=100
thin_pool_autoextend_percent=100
}
EOF
- pvcreate / vgcreate / lvcreate
yum install -y lvm2 devicemapper*
pvcreate /dev/vdb
vgcreate docker /dev/vdb
lvcreate --thinpool docker -l 95%VG --wipesignatures=y
lvcreate --thinpoolmeta docker -l 1%VG --wipesignatures=y
lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
lvchange --metadataprofile docker-thinpool docker/thinpool
与direct-lvm相应,/etc/sysconfig/docker的配置为
cat <<EOF >/etc/sysconfig/docker
OPTIONS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --log-driver=json-file --storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt=dm.use_deferred_removal=true --storage-opt=dm.use_deferred_deletion=true --insecure-registry=gcr.io --insecure-registry=quay.io --insecure-registry=registry.cn-hangzhou.aliyuncs.com --insecure-registry=192.168.0.100:5000 --registry-mirror=http://138f94c6.m.daocloud.io --registry-mirror https://ip2y4bft.mirror.aliyuncs.com --label com.domain.env=test --label com.domain.bizcluster=devops --label com.domain.publicnetwork=false"
EOF
docker info
[devops@iZuf60abyslw0fgs3ar2vmZ ~]$ docker info
Containers: *
Running: *
Paused: 0
Stopped: 0
Images: *
Server Version: 1.12.1
Storage Driver: devicemapper
Pool Name: docker-thinpool
Pool Blocksize: 524.3 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file:
Metadata file:
Data Space Used: 8.299 GB
Data Space Total: 20.4 GB
Data Space Available: 12.1 GB
Metadata Space Used: 2.494 MB
Metadata Space Total: 213.9 MB
Metadata Space Available: 211.4 MB
Thin Pool Minimum Free Space: 2.039 GB
Udev Sync Supported: true
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.135-RHEL7 (2016-11-16)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: null bridge host overlay
... ...