Skip to content

Instantly share code, notes, and snippets.

@david-zw-liu
Created August 26, 2019 15:10
Show Gist options
  • Save david-zw-liu/4dc44ee31a1d459428a22b486c3c21b6 to your computer and use it in GitHub Desktop.
Save david-zw-liu/4dc44ee31a1d459428a22b486c3c21b6 to your computer and use it in GitHub Desktop.
Init a new machine as a docker host
#!/bin/bash
set -e
echo "Increase pid_max limit"
echo "kernel.pid_max=4194304" >> /etc/sysctl.conf
sysctl -p
echo "Create 4G SWAP"
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
echo "Install docker"
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
echo "Install docker-compose"
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "Increase file descriptor limit"
echo "root soft nofile 999999" >> /etc/security/limits.conf
echo "root hard nofile 999999" >> /etc/security/limits.conf
echo "session required pam_limits.so" >> /etc/pam.d/common-session
echo "session required pam_limits.so" >> /etc/pam.d/common-session-noninteractive
sed -i -E 's/\#DefaultLimitNOFILE\=/DefaultLimitNOFILE=999999/g' /etc/systemd/system.conf
read -p "Do you want to reboot now (y/n)? " -n 1 -r
echo # move to a new line (optional)
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Reboot"
reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment