Created
January 20, 2017 12:23
-
-
Save arhea/e339a1963f717e6cd80332dd26ca4511 to your computer and use it in GitHub Desktop.
Ubuntu 16.04 LTS Docker Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
apt-get update -y && apt-get upgrade -y | |
apt-get install -y linux-image-extra-$(uname -r) \ | |
linux-image-extra-virtual \ | |
unzip \ | |
git \ | |
python \ | |
lvm2 \ | |
thin-provisioning-tools \ | |
apt-transport-https \ | |
ca-certificates \ | |
auditd \ | |
ntp | |
# Configure Kernel | |
sed -i '/GRUB_CMDLINE_LINUX=""/c\GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"' /etc/default/grub | |
update-grub | |
echo "AWS_DEFAULT_REGION=$AWS_REGION" > /etc/environment | |
# Configure System Clock | |
tee /etc/ntp.conf <<EOF | |
driftfile /var/lib/ntp/drift | |
restrict default nomodify notrap nopeer noquery | |
restrict 127.0.0.1 | |
restrict ::1 | |
server 0.amazon.pool.ntp.org iburst | |
server 1.amazon.pool.ntp.org iburst | |
server 2.amazon.pool.ntp.org iburst | |
server 3.amazon.pool.ntp.org iburst | |
includefile /etc/ntp/crypto/pw | |
keys /etc/ntp/keys | |
disable monitor | |
EOF | |
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime | |
systemctl daemon-reload && systemctl enable ntpd && systemctl restart ntpd | |
# Configure the EBS drives | |
(echo n; echo p; echo 1; echo ; echo +20G; echo n; echo p; echo 2; echo ; echo +75G; echo w) | fdisk /dev/xvdb | |
# Configure Docker Graph Disk | |
groupadd docker | |
mkfs -t ext4 /dev/xvdb1 | |
mkdir -p /var/lib/docker | |
mount /dev/xvdb1 /var/lib/docker | |
chown -R :docker /var/lib/docker | |
echo "UUID=$(blkid -o value -s UUID /dev/xvdb1) /var/lib/docker ext4 defaults 1 2" >> /etc/fstab | |
# Configure Docker DeviceMapper Storage | |
pvcreate /dev/xvdb2 | |
vgcreate docker /dev/xvdb2 | |
lvcreate --wipesignatures y -n thinpool docker -l 95%VG | |
lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG | |
lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta | |
mkdir -p /etc/lvm/profile | |
tee /etc/lvm/profile/docker-thinpool.profile <<EOF | |
activation { | |
thin_pool_autoextend_threshold=80 | |
thin_pool_autoextend_percent=20 | |
} | |
EOF | |
lvchange --metadataprofile docker-thinpool docker/thinpool | |
# Create ETechAdvisors Folder | |
mkdir -p /etc/etechadvisors | |
# Configure ETechAdvisors Group | |
groupadd etechadvisors && usermod -aG etechadvisors ubuntu | |
# Install AWS CLI | |
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "/etc/etechadvisors/awscli-bundle.zip" | |
unzip /etc/etechadvisors/awscli-bundle.zip -d /etc/etechadvisors | |
/etc/etechadvisors/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws | |
# Download CloudWatch Logging | |
curl -L "https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py" -o "/etc/etechadvisors/awslogs-agent-setup.py" | |
chmod +x /etc/etechadvisors/awslogs-agent-setup.py | |
# Install and Configure the Docker Engine | |
apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D | |
tee /etc/apt/sources.list.d/docker.list <<EOF | |
deb https://apt.dockerproject.org/repo ubuntu-xenial main | |
EOF | |
apt-get update -y && apt-get install -y docker-engine | |
mkdir -p /etc/systemd/system/docker.service.d | |
tee /etc/systemd/system/docker.service.d/docker.service.conf <<EOF | |
[Service] | |
ExecStart= | |
ExecStart=/usr/bin/dockerd \ | |
--disable-legacy-registry \ | |
--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 | |
EOF | |
systemctl daemon-reload && systemctl enable docker && systemctl restart docker | |
# Configure Docker Group | |
usermod -aG docker ubuntu | |
# Restart Docker after Configuration | |
systemctl restart docker | |
# show docker version | |
docker version | |
# check docker configuration | |
docker info | |
# Reboot the Machine | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment