Skip to content

Instantly share code, notes, and snippets.

@biinari
Created August 15, 2016 14:19
Show Gist options
  • Save biinari/7870e408c84ad4f5d84cf09a1d909ae0 to your computer and use it in GitHub Desktop.
Save biinari/7870e408c84ad4f5d84cf09a1d909ae0 to your computer and use it in GitHub Desktop.
Install docker on ubuntu trusty, wily, xenial
#!/bin/bash
# Check prerequisites for docker
if [ "$(uname -m)" != "x86_64" ]; then
echo "Docker requires 64 bit host OS"
exit 1
fi
kernel_version=$(uname -r | cut -d '.' -f 1-2)
if [ "${kernel_version%%.*}" -lt 3 ] || \
( [ "${kernel_version%%.*}" -eq 3 ] && \
[ "${kernel_version##*.}" -lt 10 ] )
then
echo "Kernel version >= 3.10 required, found ${kernel_version}"
exit 1
fi
# Setup basic error handler
function EC () {
echo -e "\e[1;31mError. Exit code $?\e[m"
}
trap EC ERR
# fail on error
set -e
# echo commands before they run
set -x
# ########################
# Install docker >= 1.11.2
# ########################
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
DISTRIB_CODENAME=$(grep DISTRIB_CODENAME /etc/lsb-release | cut -d '=' -f 2)
case "$DISTRIB_CODENAME" in
'trusty' | 'wily' | 'xenial')
echo "deb https://apt.dockerproject.org/repo ubuntu-${DISTRIB_CODENAME} main" | \
sudo tee /etc/apt/sources.list.d/docker.list
;;
'precise')
echo "While precise is listed in Docker's install instructions,"
echo "it is old and requires a trusty kernel so we are not supporting it"
exit 1
;;
*)
echo "Unsupported distribution: ${DISTRIB_CODENAME}"
exit 1
;;
esac
sudo apt-get update
case "$DISTRIB_CODENAME" in
'trusty' | 'wily' | 'xenial')
sudo apt-get install -y "linux-image-extra-$(uname -r)"
;;
esac
case "$DISTRIB_CODENAME" in
'trusty')
sudo apt-get install -y apparmor
;;
esac
sudo apt-get install -y docker-engine
sudo service docker start
# Enable service if using systemd (upstart automatically enables it)
if [ -d /run/systemd/system ]; then
sudo systemctl enable docker
fi
sudo docker version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment