Created
November 27, 2018 20:28
-
-
Save brwnj/ace0d8dfacd52199afcb53dec153d293 to your computer and use it in GitHub Desktop.
AMI with docker container storage
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
# setting up AMI | |
sudo service docker stop | |
sudo rm -rf /var/lib/docker | |
# update the image | |
sudo yum update -y | |
sudo yum install -y mdadm | |
sudo yum install -y wget | |
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh | |
bash Miniconda3-latest-Linux-x86_64.sh -b -f -p $HOME/miniconda | |
$HOME/miniconda/bin/conda install -c conda-forge -y awscli | |
rm Miniconda3-latest-Linux-x86_64.sh | |
echo manual | sudo tee /etc/init/docker.override | |
sudo -E su | |
# create thinpool profile; extend 20% when usage hits 80% | |
cat << 'EOF' > /etc/lvm/profile/docker-thinpool.profile | |
activation { | |
thin_pool_autoextend_threshold=80 | |
thin_pool_autoextend_percent=20 | |
} | |
EOF | |
# set the base size of the image appropriate for cpu to SSD storage ratio | |
cat << 'EOF' > /etc/docker/daemon.json | |
{ | |
"storage-driver": "devicemapper", | |
"storage-opts": [ | |
"dm.thinpooldev=/dev/mapper/docker-thinpool", | |
"dm.use_deferred_removal=true", | |
"dm.use_deferred_deletion=true", | |
"dm.basesize=200G" | |
] | |
} | |
EOF | |
# don't start docker service | |
echo "bash /etc/drive.sh" >> /etc/rc.local | |
cat << 'EOF' > /etc/drive.sh | |
service docker stop | |
rm -rf /var/lib/docker | |
n=$(ls /dev/nvme*n1 | wc -l) | |
mdadm --create --verbose /dev/md0 -R --level=stripe --raid-devices=$n /dev/nvme*n1 --force | |
pvcreate /dev/md0 | |
vgcreate docker /dev/md0 | |
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 | |
lvchange --metadataprofile docker-thinpool docker/thinpool | |
lvs -o+seg_monitor | |
service docker start | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment