Skip to content

Instantly share code, notes, and snippets.

@thetechnick
Last active August 29, 2015 14:16
Show Gist options
  • Save thetechnick/60d1a52f96e0591f3027 to your computer and use it in GitHub Desktop.
Save thetechnick/60d1a52f96e0591f3027 to your computer and use it in GitHub Desktop.
CentOS7 Docker install script
#!/bin/sh
#
# Common
#
print() {
reset='\033[0m'
case $2 in
info)
color='\033[0;34m';;
success)
color='\033[0;32m';;
error)
color='\033[0;31m';;
warning)
color='\033[0;33m';;
esac
echo -e "${color}${1}${reset}"
}
error() {
print "$1" error
exit 1
}
#
# Docker
#
echo "CentOS Docker installer/updater"
echo "Installing/Updating docker"
if which docker > /dev/null;
then
print "Docker already installed - skipping ..." success
else
print "Installing docker ..." info
yum install -y docker
if [ $? -ne 0 ]
then
error "Error while installing docker"
fi
fi
#
# Download
#
print "Downloading binaries and support files ..." info
if [ -f 'docker-latest.tgz' ]
then
print "-> binaries found locally!" success
else
print "-> downloading binaries ..." info
wget https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz
fi
if [ -f 'docker.socket' ]
then
print "-> docker.socket found locally!" success
else
print "-> downloading docker.sock ..." info
wget https://raw.githubusercontent.com/docker/docker/master/contrib/init/systemd/docker.socket
fi
if [ -f 'docker.service' ]
then
print "-> docker.service found locally!" success
else
print "-> downloading docker.service ..." info
wget https://raw.githubusercontent.com/docker/docker/master/contrib/init/systemd/docker.service
fi
print "Binaries downloaded successfully" success
#
# Install
#
echo
print "Installing binaries ..." info
tar -zxf docker-latest.tgz
cp ./usr/local/bin/docker /usr/bin/
cp -u docker.* /etc/systemd/system
rm -rf ./usr
print "Binaries installed successfully" success
print "Docker installed successfully" success
print "Use 'service docker restart' to start the docker daemon" success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment