blob: 27c8c8210b7d4113b7e35e6a7f0c120d5afbd9ff [file] [log] [blame]
Dean Troyer2aa2a892013-08-04 19:53:19 -05001#!/usr/bin/env bash
2
3# **install_docker.sh** - Do the initial Docker installation and configuration
4
5# install_docker.sh
6#
7# Install docker package and images
8# * downloads a base busybox image and a glance registry image if necessary
9# * install the images in Docker's image cache
10
11
12# Keep track of the current directory
13SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
14TOP_DIR=$(cd $SCRIPT_DIR/../..; pwd)
15
16# Import common functions
17source $TOP_DIR/functions
18
19# Load local configuration
20source $TOP_DIR/stackrc
21
22FILES=$TOP_DIR/files
23
24# Get our defaults
25source $TOP_DIR/lib/nova_plugins/hypervisor-docker
26
27SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60}
28
29
30# Install Docker Service
31# ======================
32
John Eckersberg22dece02014-02-13 16:21:24 -050033if is_fedora; then
34 install_package docker-io socat
35else
36 # Stop the auto-repo updates and do it when required here
37 NO_UPDATE_REPOS=True
Dean Troyer2aa2a892013-08-04 19:53:19 -050038
John Eckersberg22dece02014-02-13 16:21:24 -050039 # Set up home repo
40 curl https://get.docker.io/gpg | sudo apt-key add -
41 install_package python-software-properties && \
42 sudo sh -c "echo deb $DOCKER_APT_REPO docker main > /etc/apt/sources.list.d/docker.list"
43 apt_get update
44 install_package --force-yes lxc-docker socat
45fi
Dean Troyer2aa2a892013-08-04 19:53:19 -050046
47# Start the daemon - restart just in case the package ever auto-starts...
48restart_service docker
49
50echo "Waiting for docker daemon to start..."
51DOCKER_GROUP=$(groups | cut -d' ' -f1)
DennyZhangca1b8522013-11-17 15:44:32 -060052CONFIGURE_CMD="while ! /bin/echo -e 'GET /v1.3/version HTTP/1.0\n\n' | socat - unix-connect:$DOCKER_UNIX_SOCKET 2>/dev/null | grep -q '200 OK'; do
Dean Troyer2aa2a892013-08-04 19:53:19 -050053 # Set the right group on docker unix socket before retrying
54 sudo chgrp $DOCKER_GROUP $DOCKER_UNIX_SOCKET
55 sudo chmod g+rw $DOCKER_UNIX_SOCKET
56 sleep 1
57done"
58if ! timeout $SERVICE_TIMEOUT sh -c "$CONFIGURE_CMD"; then
59 die $LINENO "docker did not start"
60fi
61
Eric Windisch2dac8852014-01-31 01:25:28 -050062# Get guest container image
63docker pull $DOCKER_IMAGE
64docker tag $DOCKER_IMAGE $DOCKER_IMAGE_NAME
Dean Troyer2aa2a892013-08-04 19:53:19 -050065
Eric Windisch2dac8852014-01-31 01:25:28 -050066# Get docker-registry image
Daniel Kuffnerd1cd0c62014-02-08 12:35:48 +010067docker pull $DOCKER_REGISTRY_IMAGE
68docker tag $DOCKER_REGISTRY_IMAGE $DOCKER_REGISTRY_IMAGE_NAME