Skip to content

Instantly share code, notes, and snippets.

Created January 20, 2017 12:23
What would you like to do?
Ubuntu 16.04 LTS Docker Setup
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 \
# Configure Kernel
sed -i '/GRUB_CMDLINE_LINUX=""/c\GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"' /etc/default/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 ::1
server iburst
server iburst
server iburst
server iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
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 {
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 "" -o "/etc/etechadvisors/"
unzip /etc/etechadvisors/ -d /etc/etechadvisors
/etc/etechadvisors/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
# Download CloudWatch Logging
curl -L "" -o "/etc/etechadvisors/"
chmod +x /etc/etechadvisors/
# Install and Configure the Docker Engine
apt-key adv --keyserver hkp:// --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
tee /etc/apt/sources.list.d/docker.list <<EOF
deb ubuntu-xenial main
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
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment