安装方法一:
1、yum安装,添加yum源
# tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
yum install docker-engine -y
2、创建两个lv:data、metadata作为docker的存储,不做格式化。metadata大小在20-30G。
/dev/vg-docker/data
/dev/vg-docker/metadata
3、修改docker启动文件,添加红色部分,该方法适用于1.11版本以下,1.12以上版本请参考安装方法二中配置文件部分
vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon -H fd:// --selinux-enabled=false --storage-opt dm.datadev=/dev/vgdocker/data --storage-opt dm.metadatadev=/dev/vgdocker/metadata
4、启动docker
systemctl daemon-reload
systemctl start docker
安装方法二:
二进制文件安装
1、下载二进制文件
wget https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz
yum install -y audit-libs-python checkpolicy libcgroup libseccomp libselinux-python libsemanage-python libtool-ltdl policycoreutils-python python-IPy setools-libs docker-engine-selinux
2、压文件,将文件拷贝到/usr/bin/目录
tar zxvf docker-latest.tgz
mv docker/* /usr/bin/
3、创建两个lv:data、metadata作为docker的存储,不做格式化。metadata大小在20-30G。
/dev/vg-docker/data
/dev/vg-docker/metadata
4、设置开机启动文件
#docker version 1.11
tee /usr/lib/systemd/system/docker.service <<-'EOF'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
EnvironmentFile=/etc/sysconfig/docker
ExecStart=/usr/bin/docker daemon -H fd:// $OPTIONS
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
[Install]
WantedBy=multi-user.target
EOF
tee /usr/lib/systemd/system/docker.socket <<-'EOF'
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=root
[Install]
WantedBy=sockets.target
EOF
tee /etc/sysconfig/docker <<-'EOF'
# /etc/sysconfig/docker
# --bip: bridge IP address
# --insecure-registry: insecure private registry
# --storage-driver=devicemapper: need 2 lv (logical volume) for data and metadata
OPTIONS='--storage-driver=devicemapper --storage-opt dm.datadev=/dev/vg-docker/data --storage-opt dm.metadatadev=/dev/vg-docker/metadata --storage-opt dm.override_udev_sync_check=true'
EOF
#docker version 1.12
tee /usr/lib/systemd/system/docker.service <<-'EOF'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
EnvironmentFile=/etc/sysconfig/docker
ExecStart=/usr/bin/dockerd $OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
tee /etc/sysconfig/docker <<-'EOF'
# /etc/sysconfig/docker
# --bip: bridge IP address
# --insecure-registry: insecure private registry
# --storage-driver=devicemapper: need 2 lv (logical volume) for data and metadata
OPTIONS='--storage-driver=devicemapper --storage-opt dm.datadev=/dev/vg-docker/data --storage-opt dm.metadatadev=/dev/vg-docker/metadata --storage-opt dm.override_udev_sync_check=true'
EOF
5、启动docker
systemctl enable docker
systemctl start docker
更改docker存储根目录添加参数--graph=/data/docker