Skip to content

Instantly share code, notes, and snippets.

@shelan
Last active May 21, 2019 04:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shelan/f89d0e44cc1a9cd3c0ff to your computer and use it in GitHub Desktop.
Save shelan/f89d0e44cc1a9cd3c0ff to your computer and use it in GitHub Desktop.
#!/bin/bash
# ---------------------------------------------------------------------------
# docker-install.sh - installing docker
# Copyright 2016, <shelan@Shelans-MacBook-Pro.local>
# All rights reserved.
# Usage: docker-install.sh [-h|--help] [-h|--host hostip] [-i|--interface interface] [-u|--user user]
# Revision history:
# 2016-03-09 Created by script-generator.sh ver. 3.3
# ---------------------------------------------------------------------------
PROGNAME=${0##*/}
VERSION="0.1"
clean_up() { # Perform pre-exit housekeeping
return
}
error_exit() {
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
clean_up
exit 1
}
graceful_exit() {
clean_up
exit
}
signal_exit() { # Handle trapped signals
case $1 in
INT)
error_exit "Program interrupted by user" ;;
TERM)
echo -e "\n$PROGNAME: Program terminated" >&2
graceful_exit ;;
*)
error_exit "$PROGNAME: Terminating on unknown signal" ;;
esac
}
usage() {
echo -e "Usage: $PROGNAME [-help |--help] [-h|--host hostip] [-i|--interface interface] [-u|--user user]"
}
help_message() {
cat <<- _EOF_
$PROGNAME ver. $VERSION
installing docker
$(usage)
Options:
-help, --help Display this help message and exit.
-h, --host hostip host ip address of the machine
Where 'hostip' is the Host ip address.
-i, --interface interface Interface of the machine to use in engine url
Where 'interface' is the Interface of the engine url.
-u, --user user user name of the docker user
Where 'user' is the user name of the docker user.
_EOF_
return
}
# Trap signals
trap "signal_exit TERM" TERM HUP
trap "signal_exit INT" INT
# Parse command-line
while [[ -n $1 ]]; do
case $1 in
-help | --help)
help_message; graceful_exit ;;
-h | --host)
echo "host ip address of the machine"; shift; hostip="$1" ;;
-i | --interface)
echo "Interface of the machine to use in engine url"; shift; interface="$1" ;;
-u | --user)
echo "user name of the docker user"; shift; user="$1" ;;
-* | --*)
usage
error_exit "Unknown option $1" ;;
*)
echo "Argument $1 to process..." ;;
esac
shift
done
# Main logic
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-wily main" > /etc/apt/sources.list.d/docker.list'
sudo apt-get update
sudo apt-get -y install linux-image-extra-$(uname -r)
sudo apt-get -y install docker-engine
usermod -a -G docker $user ## add vagrant user to docker group
sudo mkdir -p /etc/systemd/system/docker.service.d/
sudo echo "[Service]" >> /etc/systemd/system/docker.service.d/docker.conf
sudo echo "ExecStart=" >> /etc/systemd/system/docker.service.d/docker.conf
sudo echo "ExecStart=/usr/bin/docker daemon -H fd:// --cluster-store=consul://$hostip:8500 --cluster-advertise=$interface:2375 -H=tcp://0.0.0.0:2375 -H=unix:///var/run/docker.sock" >> /etc/systemd/system/docker.service.d/docker.conf
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
graceful_exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment