Monday, February 8, 2016

Docker on CentOS 7 - proxies, yum repo, LVM, ...

By default CentOS 7 (and RHEL) use a not-so-good filesystem for Docker.
Here's the instructions to use Copy-on-Write LVM volumes instead.  This will give a vastly superior experience when using Docker on CentOS 7.
## Setup LVM
rm -rf /var/lib/docker
pvcreate /dev/
vgcreate docker /dev/
lvcreate -l 95%VG -n data docker  ## creates a large data partition
lvcreate -l 100%FREE -n meta docker  ## creates a small metadata partition


You'll need to reconfigure the service too.  This is done by a "drop-in" file for systemd.
If you need proxies for the Docker Engine, configure them here too.

## Reconfigure the service
mkdir /etc/systemd/system/docker.service.d
tee /etc/systemd/system/docker.service.d/custom.conf <<-'EOF'
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --storage-driver=devicemapper --storage-opt dm.datadev=/dev/docker/data --storage-opt dm.metadatadev=/dev/docker/meta --iptables=false
Environment='HTTP_PROXY=http://192.0.2.22:8080' 'NO_PROXY=localhost'
EOF
## if this is modified later, do this: systemctl daemon-reload


Now add the Docker Inc. yum repo & install docker:

## Docker repo & install rpm
tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
yum install docker-engine -y

## Systemd service
systemctl enable docker
service docker start