3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 function install_docker_ce
() {
19 # installs and configures Docker CE
20 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
21 echo "Installing Docker CE ..."
22 sudo apt-get
-qq update
23 sudo apt-get
install -y apt-transport-https ca-certificates software-properties-common
24 curl
-fsSL https
://download.docker.com
/linux
/ubuntu
/gpg | sudo APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE
=1 apt-key add
-
25 sudo add-apt-repository
"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
26 sudo apt-get
-qq update
27 sudo apt-get
install -y docker-ce
28 # echo "Reconfiguring Docker to use systemd as cgroup driver"
29 # if [ ! -f /etc/docker/daemon.json ]; then
30 # sudo bash -c "cat <<EOF > /etc/docker/daemon.json
32 # \"exec-opts\": [\"native.cgroupdriver=systemd\"],
33 # \"log-driver\": \"json-file\",
35 # \"max-size\": \"100m\"
37 # \"storage-driver\": \"overlay2\"
41 # sudo sed -i "s|native.cgroupdriver=cgroupfs|native.cgroupdriver=systemd|" /etc/docker/daemon.json
43 echo "Adding user to group 'docker'"
44 sudo groupadd
-f docker
45 sudo usermod
-aG docker
$USER
47 #sudo systemctl enable docker
48 #sudo systemctl daemon-reload
49 #sudo systemctl restart docker
50 sudo service docker restart
51 echo "... restarted Docker service"
52 if [ -n "${DOCKER_PROXY_URL}" ]; then
53 echo "Configuring docker proxy ..."
54 if [ -f /etc
/docker
/daemon.json
]; then
55 if grep -q registry-mirrors
/etc
/docker
/daemon.json
; then
56 sudo
sed -i "s|registry-mirrors.*|registry-mirrors\": [\"${DOCKER_PROXY_URL}\"] |" /etc
/docker
/daemon.json
58 sudo
sed -i "s|^{|{\n \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"],|" /etc
/docker
/daemon.json
61 sudo bash
-c "cat << EOF > /etc/docker/daemon.json
63 \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"]
67 #sudo systemctl enable docker
68 sudo systemctl daemon-reload
69 #sudo systemctl restart docker
70 sudo service docker restart
71 echo "... restarted Docker service again"
73 [ -z "${DEBUG_INSTALL}" ] ||
! echo "File: /etc/docker/daemon.json" ||
cat /etc
/docker
/daemon.json
74 sg docker
-c "docker version" || FATAL
"Docker installation failed"
75 echo "... Docker CE installation done"
76 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
80 while getopts ":D:p:-: " o
; do
83 OSM_DEVOPS
="${OPTARG}"
86 DOCKER_PROXY_URL
="${OPTARG}"
89 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL
="y" && continue
90 echo -e "Invalid option: '--$OPTARG'\n" >&2
94 echo "Option -$OPTARG requires an argument" >&2
98 echo -e "Invalid option: '-$OPTARG'\n" >&2
107 source $OSM_DEVOPS/common
/logging
109 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
110 echo "DOCKER_PROXY_URL=$DOCKER_PROXY_URL"